Sandy has asked for the wisdom of the Perl Monks concerning the following question:
While looking at node Resetting variables I was mislead by the line number of the error message.
It appears that when there is an if(){...}elsif(){...} construct that contains an error with the elsif part, the line number points to the line of the if statement.
Examples are better than words:
Result ... error is at line 11 ...use strict; use warnings; # demonstration of error message my $test = ""; my $abc = "abc"; if ($abc =~ /xyz/) { # <- LINE 7 print "nothing\n"; } #elsif ($abc =~ /[$test]/) { if ($abc =~ /[$test]/) { # <- LINE 11 print "passed 1st condition\n"; }
Unmatched [ before HERE mark in regex m/[ << HERE ]/ at D:\try3.pl lin +e 11.
But
Result ... error is at line 7 ...use strict; use warnings; # demonstration of error message my $test = ""; my $abc = "abc"; if ($abc =~ /xyz/) { # <- LINE 7 print "nothing\n"; } elsif ($abc =~ /[$test]/) { #if ($abc =~ /[$test]/) { # <- LINE 11 print "passed 1st condition\n"; }
Unmatched [ before HERE mark in regex m/[ << HERE ]/ at D:\try3.pl lin +e 7.
Very confusing. I haven't seen any documentation on this behaviour.
Sandy
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Error messages point to wrong line number in if-elsif construct
by cchampion (Curate) on Dec 21, 2004 at 22:29 UTC | |
Re: Error messages point to wrong line number in if-elsif construct
by gaal (Parson) on Dec 21, 2004 at 22:32 UTC | |
Re: Error messages point to wrong line number in if-elsif construct
by ikegami (Patriarch) on Dec 21, 2004 at 22:31 UTC |