P is for Practical | |
PerlMonks |
Array slice vs foreach and pushby chrisburel (Initiate) |
on Nov 10, 2011 at 01:58 UTC ( [id://937262]=perlquestion: print w/replies, xml ) | Need Help?? |
chrisburel has asked for the wisdom of the Perl Monks concerning the following question: Hi Perl Monks, There is a real-world application for this, but I'm going to make it simple for the sake of the example. Let's say I have an array of characters: my @chars = qw( a b c ? : ! f g )And I have a function called "getUpperCaseChars" that converts those characters to their uppercase equivalents. But for the punctuation, since it has no uppercase equivalent, it returns an undef for those indices instead:
Now after I've called getUpperCaseChars(), I can determine which ones did not have uppercase equivalents by doing something like this:
But readability is low on that, so I've changed it to a foreach:
So my question is, is using the array slice significantly more efficient?
Back to
Seekers of Perl Wisdom
|
|