Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

cLive ;-)'s scratchpad

by cLive ;-) (Prior)
on Jun 01, 2004 at 20:54 UTC ( [id://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
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found