P is for Practical | |
PerlMonks |
A more concise way to map the contents of an array.by Amblikai (Scribe) |
on Dec 30, 2012 at 12:40 UTC ( [id://1010917]=perlquestion: print w/replies, xml ) | Need Help?? |
Amblikai has asked for the wisdom of the Perl Monks concerning the following question: Hi Monks, i'm newly registered but i've been using your site for ages. I write a lot of perl at a very basic level, (I use it for all my "data mining" at work) but i'm trying to improve my knowledge and write more concise, idiomatic code. Anyway, i have an array, passed as reference. I want to make a new array from a slice of the referenced array, which contains only 1s or 0s depending on the value of the referenced array. In other words, i'm doing this:
So if the element of the referenced array, returns as true, i want the new array element to be 1, and 0 if it returns false. Is there a more concise way of doing this? Thanks in advance.
Back to
Seekers of Perl Wisdom
|
|