Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: reading from file.

by Eily (Curate)
on Nov 13, 2013 at 21:36 UTC ( #1062482=note: print w/ replies, xml ) Need Help??


in reply to Re^2: reading from file.
in thread reading from file.

You should have tried the solution ramlight gave you, it does look like what you were looking for. Maybe grep { $_ eq $input } @names instead of grep(/^$input$/, @names) would avoid some trouble with the metacharacters in $input though. And if you don't understang what it does, try and read grep's documentation :).

Another way to do it would be using a hash, because you have exists to check if a name exists (obviously) in it.

my @nameList = qw/Anna Beatrix Claude Damian/; my %names = map { $_ => 1 }, @nameList; # associate the value 1 to eac +h name in @namelist. Actually the value could be anything in this cas +e print "Anna exists" if exists $names{"Anna"}; print "Paul doesn't exist" unless exists $names{"Paul"};

And as taint already stated, chomp your strings :)


Comment on Re^3: reading from file.
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2015-07-03 07:41 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 (49 votes), past polls