Discussion Locked

Perl: Parsing filename components

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

This week's Perl e-newsletter explains how the File::Basename module makes the task of parsing filename components easier. Have you ever used the File::Basename module when you've had to parse filename components? If not, do you think you'll use this method? If you've used this module, share your experiences.

If you haven't already subscribed to the Perl e-newsletter, click here to sign up for our free TechMails:
http://nl.com.com/acct_mgmt.jsp?brand=builder

1 reply

by chanio

Hi,
I have a lot of photographs that have two extensions added at the end:
( i.e. photo.JPG.jpg )
One good way of only taking the last part as the extension would be this File::Basename declaration:
...fileparse($path,'\.[^.]*$');
as the definition of the file's extension.

Explained a little: starting at the . find all the characters that are NOT a '.'(dot) and end($) the name .
This obliges the REGEX to search a little more to find a coincidence. And to take only the last part as the real extension.

Thank you again, for your inspiring newletter!
PS: A Tk-Perl script that helps me a lot to try thing with REGEX can be downloaded here-> http://home.arcor.de/clemens.giegerich/ . You'll notice a fast increment of your experience by using this tool to try things!

This discussion is closed to new replies.