Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: I just want to understand why ...

by Anonymous Monk
on Oct 08, 2012 at 08:35 UTC ( #997770=note: print w/ replies, xml ) Need Help??


in reply to Why does testing for the existence of hash keys create the keys ?

From the other day see Re: How do you check if a key exists without creating it ?

no autovivification;

if( exists $foo->{bar}{anything}{you}{want} ){ }

Or

use Data::Diver 'Dive';

if( my $want = Dive( $foo, qw/ bar anything you want / ) ){ ... }


Comment on Re: I just want to understand why ...
Select or Download Code
Replies are listed 'Best First'.
Re^2: I just want to understand why ...
by Anonymous Monk on Oct 08, 2012 at 08:53 UTC

    And then there's the third way which requires some extra typing, but is fine for two-level or three-level hashes:

    my $r = $hashref; # better to use a short variable name here if($r->{a} and $r->{a}->{b} and exists $r->{a}->{b}->{c}) { # Do something }
Re^2: I just want to understand why ...
by Athanasius (Abbot) on Oct 08, 2012 at 09:15 UTC
    No autovivification.

    Huh?

    18:58 >perl -w -Mstrict -MData::Dumper -E "my $foo; say Dumper($foo); +if (exists $foo->{bar}{anything}{you}{want} ) { say 'hi' } say Dumper +($foo);" $VAR1 = undef; $VAR1 = { 'bar' => { 'anything' => { 'you' => {} } } }; 19:00 >

    Looks like 3 levels of autovivification to me.

    ???

    Update: See below.

    Athanasius <°(((><contra mundum

      And where is no autovivification; in your code?
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Oh, OK, I see it now. In the post by Anonymous Monk, “no autovivification” isn’t formatted as code, so I took it as a comment, didn’t realise it is part of the script! Sorry for the noise. (But, I’ve learned something useful. :-) )

        Athanasius <°(((><contra mundum

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-08 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (98 votes), past polls