Post Reply 
What Was Your First Programming Language?
07-09-2015, 01:15 AM
Post: #87
RE: What Was Your First Programming Language?
(07-08-2015 11:44 PM)Paul Berger (Canada) Wrote:  Yeah probably but I have a working knowledge of PERL and it does the job.

That's the job Larry Wall originally designed Perl to do, and it really excels at it. O'Reilly has a book on using Perl for systems administration, and if I recall correctly, the downloadable free sample chapter on their site is about exactly this - using Perl to parse log files.

And because I would rather do this than start real work for the day, here's the guessing game again, this time in Perl:

Code:

#!/usr/bin/perl
# Guessing game, writtn in Perl
print "Hi there, what's your name? ";
$name = <STDIN>;
chomp($name);
print "OK, $name, do you want to play a guessing game? ";
$play = <STDIN>;
chomp($play);
while ($play =~ /^y/i) {
    $number = int(rand(100))+1;
    print "I'm thinking of a number between 1 and 100.\n";
    print "You've got to try to guess it.\n";
    print "What's your guess? ";
    $guess = <STDIN>;
    while ($guess != $number) {
        if ($guess > $number) {print "Too high!";}
        if ($guess < $number) {print "Too low!";}
        print " What's your next guess? ";
        $guess = <STDIN>;
    }
    print "You've got it, $name!!!\n";
    print "Play again? ";
    $play = <STDIN>;
    chomp($play);
}

--- Les
[http://www.lesbell.com.au]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: What Was Your First Programming Language? - Les Bell - 07-09-2015 01:15 AM



User(s) browsing this thread: 2 Guest(s)