October 2001
Beginner
1024 pages
25h 8m
English
A Perl script is effectively similar to a shell script, such as those we saw in Chapter 13. The first line, the “interpreter line,” tells the shell which interpreter to use to run the rest of the script's contents:
#/usr/bin/perl
The rest of the script, as in shell programming, is made up of variable assignments, flow-control blocks and loops, system calls, and operations on I/O handles—to name a few fundamental parts of a script's anatomy. Here's a simple example:
#!/usr/bin/perl
$string = "Hello world!";
$hostname = `hostname`;
if ($hostname eq "uncia") {
print $string."\n";
print `date`;
}
Notice the use of C-style curly brackets to delimit the if block, rather than the “if/fi” and “case/esac” syntax of shell ...
Read now
Unlock full access