in reply to scalarmap - some new perl syntax
This isn't doing what you think it is. If "" is the initial element, it's not going to be used to join each of the elements together into a string. Well, it's not going to do so as join would do it, at least. Try it with something like ", " to see.my $fancy_join = scalarmap { $a . $b } "", 'a'..'z';
In case you don't feel like trying it, here's the results of:
print scalarmap { $a . $b } ", ", 'a'..'z';
, abcdefghijklmnopqrstuvwxyz
Here, though, $a is actually the *total* of whatever has come before in the list, where "total" means whatever you've defined it to mean in your code reference. And $b is just a lowly element. :)
So they're not on the same "level" of meaning as it were. I like using $_ inside of map blocks. If it were me, I'd change $b to $_, and $a to something special and local, like $T, for total, or something like that. I don't know.
Maybe move the inital value in front of the code block?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (tilly) 2: scalarmap - some new perl syntax
by tilly (Archbishop) on Sep 01, 2000 at 07:29 UTC | |
by ncw (Friar) on Sep 01, 2000 at 11:32 UTC | |
|
RE: RE: scalarmap - some new perl syntax
by ncw (Friar) on Sep 01, 2000 at 11:48 UTC |