Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: scoping problem?

by rocroc (Initiate)
on Dec 07, 2011 at 17:35 UTC ( #942292=note: print w/replies, xml ) Need Help??

in reply to scoping problem?


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!

Replies are listed 'Best First'.
Re^2: scoping problem?
by Anonymous Monk on Dec 07, 2011 at 18:49 UTC

    To brush up on your perl, you should check out the free book Modern Perl, a loose description of how experienced and effective Perl 5 programmers work....You can learn this too.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942292]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-03-24 22:10 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (308 votes). Check out past polls.