Thanks chromatic. Here's the script with additional tests to see what's in $_. at each point.
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";
}
}
here's the output of 'perl test.pl test.txt' (script includes "use warnings" this time, so they are included in the output)
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?