Conserving memory - was SPUG: Fw: greetings
ced at carios2.ca.boeing.com
ced at carios2.ca.boeing.com
Mon Oct 22 18:43:30 CDT 2001
>...
> 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> )
I suspect yes but even after carefully reading perlop, I'm not sure.
>? 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
#!/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
rgds,
--
Charles DeRykus
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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