Perl validating file names
If I've missed an important category, please shoot me a comment at the bottom of the page.As I'm sure you're aware, regular expressions are known by different names: regex or the increasingly infrequent regexp, and their plural regexes, regexps or regexen.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.
Then we'll have a quick look at some regex flavors you may run into.
That is indeed the most common implementation in modern languages. ([^.] ) # Greedily eat anything that is not a dot and capture that substring in group 1 \. ) # Lazily eat up anything and capture that substring in group 2 \.
It may very well be that the flavor of regex you use does not coincide with anything I use, though that would be bad luck indeed. # Match a dot (this is the dot before the file extension) ([^.] )$ # Greedily eat up anything that is not a dot, until the end of the filename, capturing that in group 3 (this is the extension) The final hash character (#) tells Opus to repeat the replace operation until there are no dots left to eat and the filename has been cleaned up.
This article shows how to write to a file using core perl.
There are much simpler and more readable ways to do that using Path:: Tiny.