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.
In reply to Re: A more concise way to map the contents of an array.
by LanX
in thread A more concise way to map the contents of an array.
by Amblikai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |