The problem was indeed the encoding of the file. opening the file via a file handle with the encoding:(UTF-16le) filter did the trick. Here is the working code:
use strict; use warnings; use Encode; my $username; my $color; my $filename = shift @ARGV; my $fh; open($fh, '<:encoding(UTF-16le):crlf', $filename); binmode STDOUT, ':encoding(UTF-8)'; while(<$fh>){ chomp; s/"//g; ($username,$color) = (split /,/,$_)[2,3]; if ('agag' =~ m/($username)/){ print STDOUT "here is the username: $username\n"; } }
Thanks so much to all of you for your help.
Interesting side note: I first learned perl back in 2001, coded a whole lot in a job I had through 2003, and got pretty proficient at it. Then, I didn't code at all (except for numerical stuff in C) until just this week, when all of a sudden I had to deal with some text files. I plowed ahead as if nothing had changed, coding in exactly the same style as I had 10 years ago. Reading all of the stuff on Unicode (by the way, those links are great Anonymous Monk), I see that that was very much the wrong choice! This is great, because it's given me a chance to learn about Unicode.
thanks again!
In reply to Re: scoping problem?
by rocroc
in thread scoping problem?
by rocroc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |