- It would seem that many have felt I have done something wrong here?
Not necessarily wrong, just another way to do it ... :-)
There are a couple of points that I would highlight with your code:
- The use of the perlfunc:map command in a void context is generally considered bad form as the strength of this function lies in the list context that it returns. The use of this function in a void context generally means that you are using the wrong function for the task - For example, where you have:
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?.
- At the point in the function where you remove the file extension and return the remaining portion of the file name, there are a couple of ways by which this could be done possibly more efficiently (not having performed code benchmarks at this point), the most immediate being the following:
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'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.