in reply to Re^2: scoping problem?
in thread scoping problem?
here's the output of 'perl test.pl test.txt' (script includes "use warnings" this time, so they are included in the output)use strict; use warnings; my $username; my $color; while(<>){ chomp; s/"//g; ($username,$color) = (split /,/,$_)[2,3]; print STDOUT "test of username: $username\n";#NEW print STDOUT "test of dollar-underscore: $_\n";#NEW ALSO if ("agag" =~ m/($username)/){ print STDOUT "here is the username: $username\n"; print STDOUT "here is dollar-underscore: $_\n"; } }
test of username: adad test of dollar-underscore: ADELMAN,John,adad,Ray test of username: agag test of dollar-underscore: AGAN,John,agag,Aditya test of username: ahah test of dollar-underscore: AHMED,John,ahah,Conor Use of uninitialized value $username in concatenation (.) or string at + test.pl line 11, <> line 4. test of username: test of dollar-underscore: Use of uninitialized value $username in regexp compilation at test.pl +line 13, <> line 4. Use of uninitialized value $username in concatenation (.) or string at + test.pl line 14, <> line 4. here is the username: here is dollar-underscore:
Note that $_ and $username are both coming out as they should (i.e. the split is working) before we get to the if statement. It just looks as though the match "agag" =~ m/($username)/ is failing. (note that the warnings are only being issued at the fourth "line" of the text file -- that is at the empty last line.)
still stumped. Perhaps I'm missing something really basic and obvious about the match operator?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: scoping problem?
by AnomalousMonk (Archbishop) on Dec 07, 2011 at 09:56 UTC | |
by rocroc (Initiate) on Dec 07, 2011 at 14:15 UTC | |
by AnomalousMonk (Archbishop) on Dec 07, 2011 at 21:41 UTC | |
by choroba (Cardinal) on Dec 07, 2011 at 14:45 UTC | |
by Anonymous Monk on Dec 07, 2011 at 15:03 UTC | |
|
Re^4: scoping problem?
by choroba (Cardinal) on Dec 07, 2011 at 09:29 UTC |