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:
my @cell_contents=map { if ($_) { 1; } else { 0; } }@$array_ref[3..10];
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A more concise way to map the contents of an array.
by LanX (Saint) on Dec 30, 2012 at 13:03 UTC | |
by muba (Priest) on Dec 30, 2012 at 13:23 UTC | |
by Amblikai (Scribe) on Dec 30, 2012 at 13:43 UTC | |
by LanX (Saint) on Dec 30, 2012 at 13:55 UTC | |
by Amblikai (Scribe) on Dec 30, 2012 at 13:59 UTC | |
by Athanasius (Archbishop) on Dec 30, 2012 at 14:42 UTC | |
| |
by LanX (Saint) on Dec 30, 2012 at 14:03 UTC | |
| |
Re: A more concise way to map the contents of an array.
by tobyink (Canon) on Dec 30, 2012 at 19:31 UTC |
Back to
Seekers of Perl Wisdom