Your skill will accomplish what the force of many cannot |
|
PerlMonks |
foreach/map equivalencyby rob_au (Abbot) |
on Nov 10, 2001 at 21:36 UTC ( [id://124572]=perlquestion: print w/replies, xml ) | Need Help?? |
rob_au has asked for the wisdom of the Perl Monks concerning the following question:
In trying to cut my code to a minimum, I have come up against a stumbling point in replacing a perfunc:foreach loop with a perlfunc:map statement - This stumbling point revolves around the following code:
To my mind, the foreach and map segments of code are equivalent - Herein lies the problem I suspect. They are not. If indeed, these pieces of code are equivalent, one could rightly expect the output arrays of each code segment to be the same for a given input. This is not occurring - Instead, the array output from the map code segment comprises of a large number of null values (one for each non-matching field) and the single result expected (and returned from the foreach code segment). And so my question is ... What am I doing wrong here? Is there a way to have map return no value (compared with null value) into the output array if a given condition on the input scalar is not met?
Ooohhh, Rob no beer function well without!
Back to
Seekers of Perl Wisdom
|
|