The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
OP writes: 1) while(<stdin>){print " I saw $_" ;} # Is thie (sic) equivalent to 2) while($_=<stdin>){ print "I saw $_" ;} so how will while loop end because undefined value in the $_ will not let the loop endIn Perl, the assignment $_ = <> doesn't necessarily make $_ "defined"? Strange isn't it? But here is how it happens:
It might be easier to think of "undefined" in Perl as "null" rather than "not yet assigned". Also, it isn't necessary for $_ to be undefined (or unassigned) for the loop to end. A while loop ends when expr in while (expr) evaluates to false. Being undefined is only one way of being false. Other ways of being false are:
Best, beth In reply to Re: "defined" in while loop Edit | Delete | Quote | Reply | Private Reply
by ELISHEVA
|
|