Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: 5.24 -> 5.28 -- what has changed in autovivification?

by haukex (Bishop)
on Apr 18, 2020 at 22:08 UTC ( #11115752=note: print w/replies, xml ) Need Help??


in reply to Re^5: 5.24 -> 5.28 -- what has changed in autovivification?
in thread 5.24 -> 5.28 -- what has changed in autovivification?

I understand that there are only two options

In core Perl, yes (Update: actually, autovivification isn't even in the core). But choroba showed one possibility, and writing a single-purpose routine isn't difficult either (I've admittedly compacted it a bit):

use warnings; use strict; sub dive { my $r = shift; $r = ref $r eq 'HASH' && exists $$r{$_} ? $$r{$_} : return for @_; return $r } use Test::More; my $h = { a => { b => { c => { d => 'e' } } } }; is dive($h, qw/ a /), $h->{a}; is dive($h, qw/ a b /), $h->{a}{b}; is dive($h, qw/ a b c /), $h->{a}{b}{c}; is dive($h, qw/ a b c d /), 'e'; is dive($h, qw/ a b c d e /), undef; is dive($h, qw/ a x /), undef; is dive($h, qw/ a b x /), undef; is dive($h, qw/ a x y /), undef; is dive($h, qw/ a b x y /), undef; is dive($h, qw/ x /), undef; is dive($h, qw/ x y /), undef; is dive($h, qw/ x y z /), undef; is_deeply $h, { a => { b => { c => { d => 'e' } } } }; done_testing;

Update: Both of the links in your post appear to be broken. I assume you were trying to link to perl5280delta and RT#127712.

Replies are listed 'Best First'.
Re^7: 5.24 -> 5.28 -- what has changed in autovivification?
by leszekdubiel (Scribe) on Apr 19, 2020 at 22:35 UTC
    Thank you for code and making links good.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-07-29 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?