http://www.perlmonks.org?node_id=11115704


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

The changes file does not list anything obvious to me.

The git repo listed in the module info unfortunately seems not to be accessible.

I'm not sure if it helps shed any light due to the refactoring, but the full set of differences between the two versions can be obtained through metacpan.

https://metacpan.org/diff/file?source=VPIT/autovivification-0.16&target=VPIT/autovivification-0.18

  • Comment on Re^3: 5.24 -> 5.28 -- what has changed in autovivification?

Replies are listed 'Best First'.
Re^4: 5.24 -> 5.28 -- what has changed in autovivification?
by haukex (Archbishop) on Apr 18, 2020 at 07:17 UTC
    #!/usr/bin/env perl use warnings; use strict; no autovivification qw{fetch store exists delete}; my $h = { a => { p => 2, q => 3 } }; print "perl ver $], autoviv ver $autovivification::VERSION:\n"; ! $$h{a}{x}{z} and print "a/x/z not\n"; __END__ perl ver 5.024004, autoviv ver 0.16: a/x/z not perl ver 5.028001, autoviv ver 0.16: a/x/z not perl ver 5.024004, autoviv ver 0.18: Can't vivify reference at a.pl line 9. perl ver 5.028001, autoviv ver 0.18: Can't vivify reference at a.pl line 9.
        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.

        > This is not possible.

        You've been given a solution by haukex in Re: 5.24 -> 5.28 -- what has changed in autovivification?.

        Do you need more details? Here's an example:

        #! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use Data::Diver qw{ Dive }; use Data::Dumper; my $h1 = {}; my $h2 = {a => {b => {c => 42}}}; for my $h ($h1, $h2) { say "Found $h->{a}{b}{c}" if Dive($h, qw( a b c )); } print Dumper $h1, $h2;
        Output:
        Found 42 $VAR1 = {}; $VAR2 = { 'a' => { 'b' => { 'c' => 42 } } };

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]