Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re: undef'ing @arrays caveat

by Kanji (Parson)
on Apr 21, 2002 at 01:16 UTC ( [id://160830]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: undef'ing @arrays caveat
in thread undef'ing @arrays caveat

I was thinking of definedness in the defined sense, but after some testing I discovered something really bizarre:

Calling defined on an array that was declared as empty versus one that had been populated and then later emptied returns different results!

use strict; my @array = ( ); foreach ( ['initially empty', sub { }], [' undef as first', sub { @array = undef }], [' emptied', sub { @array = ( ) }], [' undefed', sub { undef @array }], [' emptied again', sub { @array = ( ) }], ) { my($name,$change) = @$_; $change->(); printf "%15s: %-5s %-9s\n", $name, ( @array ? 'true' : 'false' ), ( defined(@array) ? 'defined' : 'undefined' ); } __END__ initially empty: false undefined undef as first: true defined *********** emptied: false defined <-- ** HUH?! ** undefed: false undefined *********** emptied again: false undefined

I can reproduce the results under both 5.00503 and 5.6.1, but while I was ready to start screaming 'BUUUUUUUUGGG!', I then noticed 5.6.1 also spits out the following with warnings are enabled ...

defined(@array) is deprecated (Maybe you should just omit the defined()?)

Something to watch out for, I guess!

    --k.


Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found