Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: scoping problem?

by GrandFather (Sage)
on Dec 07, 2011 at 00:23 UTC ( #942139=note: print w/ replies, xml ) Need Help??


in reply to Re: scoping problem?
in thread scoping problem?

I suspect you are still falling foul of blank lines or maybe unexpected line endings (Windows cr/lf line endings on a *nix system for example). The following code may be closer to what you need:

use strict; use warnings; open my $tempOut, '>', 'delme.txt' or die "Can't create temp file: $!\ +n"; print $tempOut <<FILE; "ADELMAN","John","adad","Ray" "AGAN","John","agag","Aditya" "AHMED","John","ahah","Conor" FILE close $tempOut; @ARGV = 'delme.txt'; while(<>){ chomp; s/"//g; my ($username,$color) = (split /,/,$_)[2,3]; next if ! defined $color; print "here is the username: $username\n" if "agag" =~ m/($usernam +e)/; }

Prints:

here is the username: agag

However you seem to be parsing a CSV file so really you should be using one of the modules designed for that task such as Text::CSV.

Oh, and you really should use warnings in addition to strict!

True laziness is hard work


Comment on Re^2: scoping problem?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (19)
As of 2015-07-30 21:11 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 (273 votes), past polls