Perl validating file names

Once the file is open we can use the in other parts of the tutorial, but now the first parameter is the file-handle and there is no(! The print() call above will print the text in the file. In any case, explicitly closing the files can be considered as a good practice.

The last line Actually this is only a warning; the script keeps running and that's why we see the word "done" printed on the screen.

Before you can write to a file you need to open it, asking the operating system (Windows, Linux, OSX, etc) to open a channel for your program to "talk to" the file. We could have defined it earlier, but usually it is cleaner to do it inside, even if it looks a bit awkward at first.

The second parameter defines the way we are opening the file.

In this case we use this short-circuit feature to write the expression. In case you need to handle characters that are not in the ASCII table, you'll probably want to save them as UTF-8. Buy his e Books or if you just would like to support him, do it via Patreon.

To do that you need to tell Perl, you are opening the file with UTF-8 encoding.

Opus is a unique tool—in my view the most important productivity tool a Windows user can have! Because for most users, an enormous amount of computer time disappears unnoticed in the black hole of file operations—looking for, moving and renaming files.

OTOH if the left hand side is FALSE then the right hand side is also executed and the result of that is the result of the whole expression. In the above code we don't check the actual resulting value of the logical expression. Otherwise just think about it as an arrow showing the direction of the data-flow: into the file on the right hand side.

Lots of Perl programs deal with text files such as configuration files or log files, so in order to make our knowledge useful it is important at an early stage to learn about file handling.

Let's first see how can we write to a file, because that seems to be easier.

On OSX, the free Text Wrangler its big brother BBEdit both claim to use PCRE.

What they don't say is that the PCRE version they use is 4.0 from 17 February 2003—or so it appears to me, as it supports from 5.0.

Leave a Reply