Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

by Kanji (Parson)
on Apr 21, 2002 at 01:16 UTC ( #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!


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-09-30 23:49 GMT
Find Nodes?
    Voting Booth?

    No recent polls found