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

Well the first version also auotovivifies.... i'm not sure what you mean about tied hashes.

Replies are listed 'Best First'.
Re^4: Possible useless use of map
by almut (Canon) on Mar 18, 2010 at 10:39 UTC

    No, $hr->{stuff} alone doesn't autovivify the element. It's the dereferencing operation

    $hr->{stuff}->{foo} ^^

    that autovivifies, not merely accessing the hash element.

    As for side effects with tied hashes, I mean that arbitrary code could be associated with the tied read operation.

      :D You're not paying attention
      $ perl -MDDS -w -le " my $hr; $hr->{stuff}; Dump($hr)" $HASH1 = {}; $ perl -MDDS -Mwarnings -le " my $hr; $hr->{stuff}; Dump($hr)" Useless use of hash element in void context at -e line 1. $HASH1 = {};
      $hr used to be undef, after $hr->{stuff} it is a hashref.

      Curiously, my little test reveals Data::Dump::Streamer breaks the -w switch .

        I see what you mean.  So, one could conclude that getting no warning in the OP's case (with map) is in fact the appropriate behavior (as the $hr->{$_} is not useless), while getting the warning with for seems more questionable  (in which case I wouldn't consider it a bug to silence a useless "Useless use of..." warning :)