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

Re: Why does this happen?

by bbfu (Curate)
on Apr 04, 2001 at 07:08 UTC ( #69536=note: print w/replies, xml ) Need Help??


in reply to Why does this happen?

You're trying to compare a scalar to an array slice (er... actually, it's not even an array slice). You have to supply just one index for the array, you can't supply several to get Perl to implicitly loop on them for you. You have to explicitly loop through the array elements, comparing each one to the input.

#!/usr/bin/perl -w use strict; print "What is your insult? "; chomp(my $input = <>); my @matching = qw/disk duck deck/; for (@matching) { if ($input eq $_) {die "bastard\n"}; }

(Updated first paragraph to be more verbose^Wclear.)

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-01-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?