Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

cLive ;-)'s scratchpad

by cLive ;-) (Parson)
on Jun 01, 2004 at 20:54 UTC ( #358582=scratchpad: print w/ replies, xml ) Need Help??

s#(<img[^>]+src\s*=\s*(?:"|'))/img#$1/foo#s

Perl6 sample code...

Simple stab:

#!/home/clive/rakudo-star/bin/perl6 my $number = 100.rand.ceiling; say "I'm thinking of a number between 1 and 100 inclusive. What is it? +"; for ^7 { my $guess = +prompt("Enter your guess:"); given $guess { when ! *.isa(Int) { say "Hey, that's not an integer!" } when * > $number { say "Too high!" } when * < $number { say "Too low!" } default { say "You got it!!!"; exit } } } say "Really? I was thinking of $number";

Class version (note, unfinished - allows infinite guesses)

#!/home/clive/rakudo-star/bin/perl6 class GuessNumGame { has $number = 100.rand.ceiling; has $guess-count = 0; has $.running is rw = True; method guess ($guess) { given $guess { when ! *.isa(Int) { say "Hey, that's not an integer!" } when * > $number { say "Too high!" } when * < $number { say "Too low!" } default { say "You got it!!!"; $.running=False } } } } my $game = GuessNumGame.new; say "I'm thinking of a number between 1 and 100 inclusive. What is it? +"; while $game.running { $game.guess( +prompt("Enter your guess:") ); }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2016-05-24 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?