Skip to Main Content
Perl by Example, Fourth Edition
book

Perl by Example, Fourth Edition

by Ellie Quigley
November 2007
Intermediate to advanced content levelIntermediate to advanced
1008 pages
20h 15m
English
Pearson
Content preview from Perl by Example, Fourth Edition

Chapter 3. Perl Scripts

Perl Scripts

Script Setup

A Simple Perl Script

Example 3.1. 

(The Script)
#!/usr/bin/perl
print "What is your name? ";
chomp($name = <STDIN>);  # Program waits for user input from keyboard
print "Welcome, $name, are you ready to learn Perl now? ";
chomp($response = <STDIN>);
$response=lc($response);  # response is converted to lowercase
if($response eq "yes" or $response eq "y"){
     print "Great! Let's get started learning Perl by example.\n";
}
else{
   print "O.K. Try again later.\n";
}
$now = localtime;  # Use a Perl function to get the date and time
print "$name, you ran this script on $now.\n";

(Output)
What is your name? Ellie Welcome, Ellie, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Programming Perl, 3rd Edition

Programming Perl, 3rd Edition

Larry Wall, Tom Christiansen, Jon Orwant
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Minimal Perl

Minimal Perl

Tim Maher

Publisher Resources

ISBN: 9780132381826Purchase book