Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Update: Jarkko has now applied this patch, so it'll be fixed in the next version of perl.

As several other respondents have noted, certain constructs should always be treated as implicit definedness tests when used in the loop condition of a while loop. Those constructs are:

  • <FILEHANDLE>
  • glob(...)
  • $variable = <FILEHANDLE>
  • $variable = glob(...)

What blakem pointed out is that this isn't working consistently, and if you write a loop of the form 1 while $variable = glob('*.pl'), then the test isn't wrapped in a defined() call, as it should be.

It's a bug in perl. A typo in the newLOOPOP function of op.c, to be precise. It can be fixed by applying the following patch (against bleadperl). I'll send the patch to p5p, and it ought to go into 5.8. Well spotted, blakem!

--- op.c.orig Mon Dec 17 13:51:32 2001 +++ op.c Mon Dec 17 13:55:47 2001 @@ -4073,7 +4073,7 @@ case OP_SASSIGN: if (k1->op_type == OP_READDIR || k1->op_type == OP_GLOB - || (k1->op_type == OP_NULL && k1->op_targ == OP_ +NULL) + || (k1->op_type == OP_NULL && k1->op_targ == OP_ +GLOB) || k1->op_type == OP_EACH) expr = newUNOP(OP_DEFINED, 0, expr); break;

In reply to It's a bug (was: When does while() test for defined vs truth) by robin
in thread When does while() test for defined vs truth by blakem

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 cooling their heels in the Monastery: (3)
As of 2024-04-24 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found