In my opinion (or "I personally believe" if you must) modifying an array with push/pop inside a map statement is one of those hints that there's a better way to go about a problem! :-)
The canonical form of map (according to me) is used to return a mapped version of the input:
@a = map {
# A function of $_, eg:
$_ . ".txt"
} @a;
One of the things I find particularly useful is that the block of code can evaluate to a list, including an empty one. Ie the output of map need not be the same length as the input. Eg
# Emulate grep with map
@a = map { elementShouldBeIncluded($_) ? $_ : () } @a;
# Double up the list
@a = map { ($_, $_) } @a;
In this particular case, this feature may be exactly what you're after, depending on how what exactly your vendor supplied program does. Consider the following structure:
@a = map {
# Is it a dir?
(-d $_) ?
# Expand it (somehow) into a list of files
turnDirIntoFilesUsingVendorProg($_)
:
# It's a file - pass it straight through
$_
} @a;
Hope that helps.
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.