Colin Watson schrieb:

On Fri, Dec 06, 2002 at 04:53:28PM +0100, J?rg Johannes wrote:

Here it comes:
In "Programming Perl (german translation) there is an example for how to skip lines that start with the hash sign:

LINE: while ($line = <INFILE>) {
next LINE if /^#/; # Should skip lines that start with the hash sign.
# what to do with non-comment-lines....
}

Instead of the second line there, you need:

next LINE if $line =~ /^#/;

... otherwise you're matching against $_, which you haven't set.

Yes, that was it. thanks.

while (<INFILE>) {
next if /^#/;
# the input line is in $_
}

while (defined($line = <INFILE>)) {
next if $line =~ /^#/;
# the input line is in $line
}


PS.: The book is written for Perl 5.006, I think, and I use 5.8 (from sid). Did the pattern matching change?

Nope, the example you quote is wrong in both.

Interesting. I will never buy books again, and ask here instead...

joerg


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to