Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Sometimes undef is initialized and sometimes not when hash values are fed to grep

by LanX (Saint)
on Feb 11, 2020 at 16:47 UTC ( [id://11112786]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11112786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found