Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Why will referencing an undefined value as array reference create a real array

by jeffa (Chancellor)
on Jun 18, 2014 at 18:54 UTC ( #1090334=note: print w/ replies, xml ) Need Help??


in reply to Why will referencing an undefined value as array reference create a real array

That's a feature called auto-vivification. Consider the following alternative:

print "this won't be printed\n" if (scalar @{$test} and scalar @{$test +}[0]);


jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re: Why will referencing an undefined value as array reference create a real array
Select or Download Code
Re^2: Why will referencing an undefined value as array reference create a real array
by mfort (Initiate) on Jul 28, 2014 at 15:46 UTC
    Thanks for pointing me to the Auto Vivification. I swear I learn something new every day with perl and I've been using it for decades now.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-09-02 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (21 votes), past polls