Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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 contemplating the Monastery: (5)
As of 2018-06-22 00:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.