J
John Markos O'Neill
Yesterday someone suggested to me that it was possible to do something
to each element in an array without an iterative (say, a foreach)
loop. Well, actually, they said it could be done in one line but I
assume they didn't just mean it would be done with an aesthetically
displeasing removal of white space.
In my experience, the least-lines-of-perl way to, say, print out all
of the even elements in an array would be something like
@array = (1, 2, 3, 4, 5, 6, 7, 8);
foreach $array_ele (@array) {
($array_ele % 2 == 0) &&
($even_array_ele = $array_ele) &&
print("\$even_array_ele: $even_array_ele\n");
}
For the sake of this discussion, let's call the three-line statement
in the foreach loop a single line. Is it possible to do this with
fewer statements? If so, how?
Thanks,
John Markos O'Neill
to each element in an array without an iterative (say, a foreach)
loop. Well, actually, they said it could be done in one line but I
assume they didn't just mean it would be done with an aesthetically
displeasing removal of white space.
In my experience, the least-lines-of-perl way to, say, print out all
of the even elements in an array would be something like
@array = (1, 2, 3, 4, 5, 6, 7, 8);
foreach $array_ele (@array) {
($array_ele % 2 == 0) &&
($even_array_ele = $array_ele) &&
print("\$even_array_ele: $even_array_ele\n");
}
For the sake of this discussion, let's call the three-line statement
in the foreach loop a single line. Is it possible to do this with
fewer statements? If so, how?
Thanks,
John Markos O'Neill