Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: reading from file.

by Eily (Parson)
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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062482]
help
Chatterbox?
[ambrus]: it now has two more people working there, and they're serving slower and more expensive.
[ambrus]: It used to be just a master cook who takes the order and puts the meat and eggs on the open grill plate table, and an assistant who removes them to a plate, adds the side dish, and gives the plate to the people in the queue, plus a cashier.
[ambrus]: Now it has five people instead of three, some sort of call number ticket system where people wait a lot for their food to get ready (it's the same kinds of grilled meat and fish on the same equipment, it won't actually fry slower),
[ambrus]: it's slow as hell, and the food costs significantly more.
[ambrus]: We no longer eat there.
LanX Everybody quotes it, some people read it, and a few people go by it
[ambrus]: LanX: why would I read it? isn't it a book for managers? I don't want to be a manager.
[ambrus]: I don't quote it either.
[erix]: it's really a software book, albeit about experiences from the 60s-80s. People haven't changed all that much though.
[erix]: a software project book, is probably more exact

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2017-09-22 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (264 votes). Check out past polls.

    Notices?