From: "Gerald Host" <[EMAIL PROTECTED]>
> I'm trying to read a text file line-by-line.
>
> open IN, shift;
> my @lines=split("\n",<IN>);
Did you ever read the docs???
my @lines=<IN>;
The <> operator returns the list of lines in the file if called in
the list context.
> foreach my $line (@lines) {
> print OUT "QQQ $line QQQ\n";
> }
>
> The problem is that it always gives me the entire file, not line by
> line. What did I do wrong? Other things I've tried:
>
> open IN, shift;
> while (my $line =<IN>) {
> print OUT "QQQ $line QQQ\n";
> }
This one should work.
Are you sure you did not touch $/ beforehand? This is the variable
that specifies what's the line delimiter. If you undefine it you'll
get the whole file as the first and only line.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>