Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

lowphive's scratchpad

by lowphive (Monk)
on Oct 14, 2006 at 16:11 UTC ( #578297=scratchpad: print w/replies, xml ) Need Help??

#!/usr/bin/perl %words = qw( fred camel barney llama betty alpaca wilma alpaca ); print "What is your name? "; $name = <STDIN>; chomp ($name); if ($name =~ /^randal\b/i) { # back to the other way :-) print "Hello, Randal! How good of you to be here!\n"; } else { print "Hello, $name!\n"; # ordinary greeting print "What is the secret word? "; $guess = <STDIN>; chomp ($guess); while (! good_word($name, $guess)) { print "Wrong, try again. What is the secret word? "; $guess = <STDIN>; chomp ($guess); } } sub good_word { my($somename, $someguess) = @_; # name the parameters $somename =~ s/\W.*//; # get rid of everything after first word $somename =~ tr/A-Z/a-z/; # lowercase everything if ($somename eq "randal") { # should not have to guess return 1; # return value is true } elsif ($someguess eq ($words{$somename} || "groucho")) { return 1; # return value is true } else { return 0; # return value is false } }
Log In?

What's my password?
Create A New User
[shmem]: have a good time inside your information bubble.
[erix]: perhaps we can have common hindsight at these thing in a few years time
[Your Mother]: Please don't fight, mom and dad!

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-03-19 21:21 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.