One, example one
#!/usr/bin/perl
print "What ' s your name?";
Chomp ($name = <STDIN>);
Print "Welcome, $name, are you ready learn Perl now?"
Chomp ($response = <STDIN>);
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;
Print "$name, ran this script on $now. \ n";
Explain
01 lines are labeled Interpreter is Perl execution
02 Print to screen output with print, Perl "Display content" with print;
03chomp remove the last character, that is, remove the line feed
$name = <STDIN> is to set a variable $name from the standard input <stdin>
Note that the variables in Perl are the $ start
Note that Perl variables can be used without a statement, very flexible
Run as follows
04 and 05.
06 is an If statement to judge, the format is
if (condition 1 is established) {
EXECUTE statement 1
}
else {
EXECUTE statement 2
}
$response eq "yes" or $response eq "y" means that the value of the variable $response is yes or Y
12 is to set a variable now, from Perl's built-in functions localtime
13 is the display