in reply to Re: Re: Parse out the extension of a filename - return base of filename.
in thread Parse out the extension of a filename - return base of filename.
Not necessarily wrong, just another way to do it ... :-)
There are a couple of points that I would highlight with your code:
map { push(@pieces,$_) } split(/\./,$file);
It would be much better to perform this with a simple for or foreach loop. eg.
push( @pieces, $_ ) foreach split( /\./, $file );
This is also referenced in the node - What's wrong with using grep or map in a void context?.
pop @pieces; return join '.', @pieces;
In this instance, there is no need for the regular expression against the original file name or test for definition of file name as join will return an empty string if @pieces is empty.
One aspect about your code however that did seem redundant given that the functionality which you are seeking is available within File::Basename (see my node here for a code example that gives you exactly what you desire from the fileparse method).
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'
|
|---|