in reply to A more concise way to map the contents of an array.
you could use the conditional operator aka "ternary operator" :
my @cell_contents = map { $_ ? 1 : 0 } @$array_ref[3..10];
another idea is to use doubled negation "!!" and to map the empty string (false) to 0.
my @cell_contents = map { 0 + !!$_ } @$array_ref[3..10];
but I don't think this conciseness justifies the loss of readability.¹
Cheers Rolf
¹) well if you really need 0 for false.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A more concise way to map the contents of an array.
by muba (Priest) on Dec 30, 2012 at 13:23 UTC | |
Re^2: A more concise way to map the contents of an array.
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 Amblikai (Scribe) on Dec 30, 2012 at 16:11 UTC | |
by LanX (Saint) on Dec 30, 2012 at 14:03 UTC | |
by Amblikai (Scribe) on Dec 30, 2012 at 14:31 UTC |
In Section
Seekers of Perl Wisdom