in reply to Re: Sometimes undef is initialized and sometimes not when hash values are fed to grep (already discussed)
in thread Sometimes undef is initialized and sometimes not when hash values are fed to grep

Here two or three workarounds (can't test the latter)

use utf8; use strict; use warnings; use Data::Dumper; my %h = (a => 'alfa', b => 'beta'); print "\n\nWorkaround 1 \n"; print map { "\t>>$_<<\n" } "$h{a}", "$h{111}", "$h{b}"; print "after third:\n", Dumper(\%h); print "\n\nWorkaround 2 \n"; print map { "\t>>$h{$_}<<\n" } qw/a 222 b/; print "after third:\n", Dumper(\%h); # print "\n\nWorkaround 3 \n"; # no autovivification; # print map { "\t>>$_<<\n" } $h{a}, $h{333}, $h{b}; # print "after third:\n", Dumper(\%h);

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^2: Sometimes undef is initialized and sometimes not when hash values are fed to grep
  • Download Code

Replies are listed 'Best First'.
Re^3: Sometimes undef is initialized and sometimes not when hash values are fed to grep
by haukex (Archbishop) on Feb 11, 2020 at 16:51 UTC
    can't test the latter

    Unfortunately, that one doesn't work:

    use warnings; use strict; use Data::Dumper; no autovivification; my %h = (a => 'alfa', b => 'beta'); print map { ">>$_<<\n" } $h{a}, $h{333}, $h{b}; print Dumper(\%h); __END__ Use of uninitialized value $_ in concatenation (.) or string at 111127 +86.pl line 8. >>alfa<< >><< >>beta<< $VAR1 = { '333' => undef, 'a' => 'alfa', 'b' => 'beta' };
      ugh .... :/

      But I seem to remember that this glitch was also mentioned in the last thread.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice