Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.



In reply to Re: Re: Re: undef'ing @arrays caveat by Kanji
in thread undef'ing @arrays caveat by vladb

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 making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found