in reply to Re: Possible useless use of map
in thread Possible useless use of map

What bug? In:
map {$hr->{stuff}} 1
there is no hash element in void context. It's in list context.

Replies are listed 'Best First'.
Re^3: Possible useless use of map
by Anonymous Monk on Mar 18, 2010 at 14:48 UTC
    perl590delta says map in void context is no longer expensive. map is now context aware, and will not construct a list if called in void context.

    if there is no list, why is there list context?

      Just like about any other operator in Perl, map imposes a certain context on its operands, regardless of the context it itself is in. In:
      map {$hash->{foo}} 1;
      there are actually two lists, both containing a single element: the first list consists of $hash->{foo}, the second of 1.

      Think of it this way, if map would not provide list context to its inner block, the following wouldn't do what it does now:

      %h = map {$_ => 1} qw[foo bar baz];