in reply to Re^2: using shift and $_ in loop
in thread using shift and $_ in loop
sub alter { my @newlist; for ( @_ ){ my $name = is_name($_) or next; push @newlist, uc($name); } @newlist; }
I'd write that as
sub alter { grep $_, map { uc is_name($_) } @_; }
instead.
In Perl 6 I'd maybe write something more similar to what you wrote:
sub alter(*@a) { gather for @a { my $name = is_name($_); take uc $name if $name; } }
Or even
sub alter(*@a) { gather for @a.map({ is_name($_)}) { take .uc if $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: using shift and $_ in loop
by leocharre (Priest) on Oct 21, 2009 at 21:01 UTC | |
by moritz (Cardinal) on Oct 21, 2009 at 21:51 UTC | |
by ikegami (Patriarch) on Oct 21, 2009 at 21:10 UTC | |
by leocharre (Priest) on Oct 21, 2009 at 21:16 UTC |