Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: Animals

by merlyn (Sage)
on May 05, 2000 at 18:58 UTC ( #10368=note: print w/ replies, xml ) Need Help??


in reply to Animals

Here's my version of that, which I wrote for a UnixReview column but never got around to it...

#!/usr/bin/perl -w use strict; use Data::Dumper; my $info = "dog"; { try($info); redo if (yes("play again?")); } print "Bye!\n"; print Dumper($info); sub try { my $this = $_[0]; if (ref $this) { return try($this->{yes($this->{Question}) ? 'Yes' : 'No' }); } if (yes("Is it a $this")) { print "I got it!\n"; return 1; }; print "no!? What was it then? "; chomp(my $new = <STDIN>); print "And a question that distinguishes a $this from a $new would b +e? "; chomp(my $question = <STDIN>); my $yes = yes("And for a $new, the answer would be..."); $_[0] = { Question => $question, Yes => $yes ? $new : $this, No => $yes ? $this : $new, }; return 0; } sub yes { print "@_ (yes/no)?"; <STDIN> =~ /^y/i; }

-- Randal L. Schwartz, Perl hacker


Comment on RE: Animals
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-12-25 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls