perl-asp mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henrik Tougaard <ht...@foa.dk>
Subject RE: intermittent failure reading a file
Date Mon, 18 Jun 2001 04:42:31 GMT
> -----Original Message-----
> From: Joshua Chamas [mailto:joshua@chamas.com]
>
> I don't know that while(<IN>) is a good idea,
> I wonder what would happen if somehow a line
> was blank, would that be boolean 0 ?  Try 
> instead:  for(<IN>), or even
> 
>  my @lines = <IN>
>  for ( @lines ) {

That shouldn't be neccessary. The construct
   while (<IN>) {
is a specialcased as a shorthand for
   while (defined($_ = <IN>)) {

See `perldoc perlsyn`:
  For example, when processing a file like /etc/termcap.  If your input
lines
  might end in backslashes to indicate continuation, you want to skip ahead
  and get the next record.

      while (<>) {
          chomp;
          if (s/\\$//) {
              $_ .= <>;
              redo unless eof();
          }
          # now process $_
      }

  which is Perl short-hand for the more explicitly written version:

      LINE: while (defined($line = <ARGV>)) {
          chomp($line);
          if ($line =~ s/\\$//) {
              $line .= <ARGV>;
              redo LINE unless eof(); # not eof(ARGV)!
          }
          # now process $line
      }

--
Henrik Tougaard, FOA. Denmark.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Mime
View raw message