in reply to Re: Re: Using s///e and it just doesn't feel right
in thread Using s///e and it just doesn't feel right

map should not be used in a void context, that's why foreach is there.

And why then is map allowed to be called in void context? =)

-Waswas
  • Comment on Re: Re: Re: Using s///e and it just doesn't feel right

Replies are listed 'Best First'.
Re: Re: Re: Re: Using s///e and it just doesn't feel right
by bunnyman (Hermit) on Jun 20, 2003 at 16:44 UTC
    It is addressed in the Perl FAQ.

    There are a lot of things you can do with Perl that you shouldn't do.

      #!/usr/bin/perl use strict; sub bob { map { print "$_$/" } @_; } my @thing = qw(tom dick harry); bob(@thing); print "============$/"; my @results = bob(@thing); print "We printed " . (scalar @results) . " items$/";

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1

        but that uses the return from map, although it's hidden.

        I don't see why using map in a void context is so wrong. Sometimes it expresses something better, particularly if the order of operation doesn't matter:

        map {transform($_)} @elements; # transform() does something inline
        A massive flamewar beneath your chosen depth has not been shown here