in reply to Re: Re: "foreach" is to "next" as "map" is to ???
in thread "foreach" is to "next" as "map" is to ???
The empty list trick, while very cool, is not equivalent to next.So, there is a difference? Let's see what that should be.
The empty list trick is just preventing the map block from returning a value for that input item - it still has to execut every step in the block first.Really? Let's see, we take a list of numbers, and for all odd numbers, we print the square of the number, and return the number. The even numbers are skipped. According to your theory, the following code would print the squares of all the numbers:
my @odds = map {$_ % 2 ? do {print $_ * $_; $_} : ()} 1 .. 10;
However, if I run it, it only prints the numbers 1, 9, 25, 49 and 81. I guess either my perl is broken, or your theory is false.
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: "foreach" is to "next" as "map" is to ???
by Limbic~Region (Chancellor) on May 26, 2004 at 16:59 UTC | |
by Abigail-II (Bishop) on May 26, 2004 at 17:23 UTC | |
by Limbic~Region (Chancellor) on May 26, 2004 at 17:30 UTC | |
by diotalevi (Canon) on May 26, 2004 at 17:22 UTC |