in reply to Re: Perl autovivifyies object property when using exists
in thread Perl autovivifyies object property when using exists

Nice. I figured there was some pragma-like way to change this behavior, but never heard of "no autovivification".
  • Comment on Re^2: Perl autovivifyies object property when using exists

Replies are listed 'Best First'.
Re^3: Perl autovivifyies object property when using exists
by LanX (Saint) on Apr 04, 2024 at 19:26 UTC
    It's worth noting that the default behavior of no autovivification doesn't disable it in case of assignments aka store

    Which is great because that's DWIM for most. But surprising given the name of the pragma...

    DB<5> no autovivification; $h->{a}{b}{c} = 42 DB<6> x $h 0 HASH(0xb400007e0b2fd8b8) 'a' => HASH(0xb400007e0b2ea7f8) 'b' => HASH(0xb400007e0b2eac30) 'c' => 42 DB<7>

    From the autovivification docs

    Possible unimports:

    • no autovivification qw<fetch store exists delete>;
    But store is not default
    • no autovivification; # defaults to qw<fetch exists delete>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Assignment "store" was the first thing I tested when I installed it yesterday :)