Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Whenever a non-existing hash or array element is used in anything but a simple context, it's autovivificated. The *default* is to autovivificate - it's just that the exceptions happen to be the most often used cases, so it's a surprise when perl autovivifies.
#!/usr/bin/perl use strict; use warnings; my %hash; sub X {} my $x; $x = exists $hash{key1}; printf "key1 %sautovivified\n", exists $hash{key1} ? "" : "not "; $x = $hash{key2}; printf "key2 %sautovivified\n", exists $hash{key2} ? "" : "not "; $x = exists $hash{key4}{key3}; printf "key3 %sautovivified\n", exists $hash{key4}{key3} ? "" : "not +"; printf "key4 %sautovivified\n", exists $hash{key4} ? "" : "not "; ($x) = @hash{key5}; printf "key5 %sautovivified\n", exists $hash{key5} ? "" : "not "; ($x) = @hash{"key6", "key7"}; printf "key6 %sautovivified\n", exists $hash{key6} ? "" : "not "; printf "key7 %sautovivified\n", exists $hash{key7} ? "" : "not "; X($hash{key8}); printf "key8 %sautovivified\n", exists $hash{key8} ? "" : "not "; X(@hash{key9}); printf "key9 %sautovivified\n", exists $hash{key9} ? "" : "not "; X(@hash{"keyA","keyB"}); printf "keyA %sautovivified\n", exists $hash{keyA} ? "" : "not "; printf "keyB %sautovivified\n", exists $hash{keyB} ? "" : "not "; __END__ key1 not autovivified key2 not autovivified key3 not autovivified key4 autovivified key5 not autovivified key6 not autovivified key7 not autovivified key8 not autovivified key9 autovivified keyA autovivified keyB autovivified
Perl --((8:>*

In reply to Re^2: Autovivification sucking the life out of me by Perl Mouse
in thread Autovivification sucking the life out of me by shenme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found