Perl: the Markov chain saw PerlMonks

### cLive ;-)'s scratchpad

by cLive ;-) (Prior)
 on Jun 01, 2004 at 20:54 UTC Need Help??

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

# 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";
[download]```

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:") );
}
[download]```
Log In?
 Username: Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2017-08-19 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (310 votes). Check out past polls.

Notices?