Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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?

SOLVED!!!!!

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!


Comment on Re: scoping problem?
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942292]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2015-07-31 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls