in reply to Perl autovivifyies object property when using exists

$ perl -MData::Dump -E '$fs4={_structure=>{"/Users/dotfiles/perl5/my_ +modules"=>{}}};my $b= $fs4->{_structure}{"/Users/dotfiles/perl5/my_mo +dules"};say (exists $b->{BLAH} and exists $b->{BLAH}{crap}); say dd( +$fs4)'
output:
{ _structure => { "/Users/dotfiles/perl5/my_modules" => {} } } 1

                "If it happens once, it's a bug. If it happens twice, it's a feature. If it happens more than twice, it's a design philosophy."

Replies are listed 'Best First'.
Re^2: Perl autovivifyies object property when using exists
by nysus (Parson) on Apr 03, 2024 at 19:12 UTC

    Oh, I see the second exists call in there now. Missed it the first time.

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks

Re^2: Perl autovivifyies object property when using exists
by nysus (Parson) on Apr 03, 2024 at 18:59 UTC

    This reproduces the problem:

    perl -MData::Dump -E ' my $fs4 = {'_structure' => {}}; exists $fs4->{_ +structure}{BLAH}{TEST}{Crap}; dd $fs4->{_structure} '

    Output: { BLAH => { TEST => {} } }

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks

Re^2: Perl autovivifyies object property when using exists
by nysus (Parson) on Apr 03, 2024 at 18:50 UTC

    I'm at a loss. I get the same as you on the command line. But in my test, running this:

    my $fs4 = {'_structure' => {}}; say (exists $fs4->{_structure}{'/Users/dotfiles/perl5/my_modules'}{BL +AH}{Crap}); d $fs4->{_structure}, 3;

    I get this:

    $VAR1 = { '/Users/dotfiles/perl5/my_modules' => { 'BLAH' => {} } };

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks