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 $_; } }
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^4: using shift and $_ in loop
by leocharre (Priest) on Oct 21, 2009 at 21:01 UTC
    Are you going around tempting people to use perl6? I've looked at some specs.. pretty freaking interesting- a little scary too. Like "defined or" .. //= very sexy.. I wonder is all this stuff I'm looking at here actually implemented? Wild.
      Are you going around tempting people to use perl6?

      Yes. In fact that's how Perl got popular in the first place: people posted easy Perl solutions to problems that were posted in usegroups which got typically answered with examples in shell scripts, sed or awk.

      I wonder is all this stuff I'm looking at here actually implemented?

      I haven't tried them, but the examples I gave you use only features that are implemented in Rakudo.

      Perl 6 - links to (nearly) everything that is Perl 6.

      // and //= are present in 5.10

        Yeah? But perl 5.10 is not present on any of my servers.. Not that it couldn't be made to... hmm.. I suppose maybe that's gonna be the hurdle to getting p6 popular, eh? Getting the compiler/interpreter to actually be widely available. . Ok I shut up now, way off topic- reading up on some super useful p5 to p6 lit.