Re: [OT] Perl pattern matching
On Friday 06 December 2002 16:53, Jörg Johannes wrote:
> Hi List
>
> Sorry for coming in here with such a question, but this list ahs perl
> gurus, and response is much faster than comp.lang.perl.misc (and I need
> the answer fast...)
>
> 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....
> }
>
I think, the problem is, that you assign to $line but test to $_, which
in fact is not set.
So either change your code to :
LINE: while (<INFILE>) {
next LINE if /^#/; # Should skip lines that start with the hash sign.
# what to do with non-comment-lines....
}
or to
LINE: while ($line = <INFILE>) {
next LINE if $line =~ /^#/; # Should skip lines that start with the hash sign.
# what to do with non-comment-lines....
}
> When I try to use it, I get an error message:
> Use of uninitialized value in pattern match (m//) at ./rhodanid.pl line
> 138, <INFILE> line 1
> for all lines of the file coming in via <INFILE>
>
> Any idea how to skip comment-lines?
>
> thanks
> joerg
>
> PS.: The book is written for Perl 5.006, I think, and I use 5.8 (from
> sid). Did the pattern matching change?
Don't know and don't think so.
HTH, Michael
Reply to: