should do the trick. In this code fragment I'm looking for a real period, followed by any number of word characters, followed by the end of the string. I put that in brackets so that I can grab it as $1 later on.$FileName = "/var/log/apache/error.log"; $FileName =~ m/\.(\w*)$/; $Extension = $1;
This of course makes the assumption that your definition of a file extension is the group of characters to the right of the last period in a file name .. so the file extension of "foo.bar.baz" would be "baz". Your code should also handle the situation where there are no periods in the filename.
ps I highly recommend reading Programming Perl (Third Edition) by Wall, Christiansen & Orwant, published by O'Reilly.
"Excellent. Release the hounds." -- Monty Burns.
In reply to Re: Extract string from rear of string
by talexb
in thread Extract string from rear of string
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |