Conserving memory - was SPUG: Fw: greetings

Jason Lamport jason at strangelight.com
Mon Oct 22 14:34:30 CDT 2001


At 9:01 AM -0700 10/22/01, David Dyck wrote:
>On Sun, 21 Oct 2001, Jason Lamport wrote:
>
>>  At 11:27 AM -0700 10/21/01, Jeremy Devenport wrote:
>>  >
>>  >1) You don't need to check for defined inside a while loop condition if
>>  >it is of the form <FILE> or $var = <FILE>. Perl does this for you.
>>
>>  Is this true for all versions of Perl?  I seem vaguely to recall that
>>  this was a fairly recent (post 5.004) enhancement.  But I could be
>>  mis-remembering.
>
>the file Changes5.001 in the perl source distribution indicates reports
>the following patch
>
>NETaa13486: while (<>) now means while (defined($_ = <>))
>From: Jim Balter
>Files patched: op.c pod/perlop.pod
>  while (<HANDLE>) now means while (defined($_ = <HANDLE>)).
>
>perldoc perlhist contains the release date for 5.001 as
>    Larry   5.001          1995-Mar-13
>
>     (Do you call 1995-Mar-13 recent? :-)

No, but I was referring particularly to the

while( $var = <FILE> )

variant.  I believe that in 5.004 (and earlier) this is NOT 
semantically equivalent to

while( defined($var = <FILE>) )

------
Hmmm... so just out of perverse curiosity, what would be the most 
efficient way of generating the old behaviour in a newer version of 
Perl?

while( ($var = <FILE>) ? 1 : undef )	# ?????

Actually, this isn't just perverse curiosity: I'd like to know under 
*exactly* what set of conditions while(*) actually means while( 
defined(*) ) .  Is it only in the very specific cases of

while(<FOO>)
while( $var = <FOO> )

?  Is it anytime the <> operator appears in the expression?  E.g. 
what would be the semantics of:

while( ($var = <FOO>) , $var )

?

-jason

P.S. and yes, I know I used unnecessary parentheses in some of the 
above expressions.  I have better things to do with my brain cells 
than memorize operator-precedence tables...   :-P

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list