> From: "Rodney Wines" <[EMAIL PROTECTED]>
> > > From: [EMAIL PROTECTED]
> > > open (IN, "a.txt") ;
> > > while (<IN>) {
> > > chomp ($line = <>);
> > > # $line contains line from a.txt
> >
> > No $line contains a line from a file whose name is in @ARGV or from
> > STDIN. You wanted
> > $line = <IN>
> > !!!
>
> No ... :-)
>
> The "while(<IN>)" reads a line into $_. So, just "chomp;" is required inside
> the loop.
>
> "$line = <IN>" would get the next line from the file, and $line would only
> contain every other line of IN as the loop executed ...
Well. Sure if the code realy looked like that.
I expected in the actual code there will be something between the
while() and chomp($line = <>). :
while (<>) {
... some code
if (we_need_next_line) {
chomp($line = <IN>);
... some more code
The problem I was trying to highlight is that in the while() the
original poster reads from IN, while in the other statement he reads
from a file in @ARGV or STDIN.
The code proposed was :
while (<IN>) {
chomp ($line = <>);
Do you see? He is reading from the same filehandle.
I think he wanted to write
while (<IN>) {
chomp ($line = <IN>);
BTW, if there was no code before these two lines he would get every
other line in $_ and the other lines in $line. So he could process
the whole file this way, if he was carefull.
Jenda
== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
: What do people think?
What, do people think? :-)
-- Larry Wall in <[EMAIL PROTECTED]>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl