Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Perl Programming/Simple examples 2

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Perl Simple examples 1 Concept index Hi-Lo: A simple game written in perl that asks you for a guess between 1 and 100 and tells you if you are too high or low. use warnings; use strict; $| = 1; print "Enter number of games to play: "; chomp(my $Num_Games = <STDIN>); my $Num_Guesses = 0; for my $gameno (1 .. $Num_Games) { my $number = 1 + int rand 100; my $guess; do { print "Enter guess from 1 to 100: "; chomp($guess = <STDIN>); ++$Num_Guesses; if ($guess < $number) { print "Higher!\n"; } elsif ($guess > $number) { print "Lower!\n"; } } until $guess == $number; print "Correct!\nAverage guesses per game: ", $Num_Guesses / $gameno, "\n\n"; } print "Games played: $Num_Games\n"; Perl Simple examples 1 Concept index