Conserving memory - was SPUG: Fw: greetings
Matt Tucker
tuck at whistlingfish.net
Tue Oct 23 15:20:24 CDT 2001
-- ced at carios2.ca.boeing.com spake thusly:
>> ? Is it anytime the <> operator appears in the expression? E.g.
>> what would be the semantics of:
>
>> while( ($var = <FOO>) , $var )
>
> With an added chomp, your line above does appear to recapture the
> older semantics. The following prints:
>
> abc
> def
> 0
> abc
> def
Printing the '0' is appropiate even with older semantics. The problem,
I believe, only arose when the separator character was itself
evaluatable (is that a word?) as false. Doing the chomp completely
changes the loop, since it requires that all the code within know that
the separator has been stripped.
># !/usr/bin/perl -w
> use strict;
> my $start = tell DATA;
> print while <DATA>;
> seek(DATA, $start, 0) or die;
> my $var;
> while( chomp($var = <DATA>), $var ) {
> print $var, "\n";
> }
> __END__
> abc
> def
> 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20011023/255e51b5/attachment.bin
More information about the spug-list
mailing list