Fundamentals of Perl Scripting

A Perl script is effectively similar to a shell script, such as those explained in Chapter 10. The first line (known as the interpreter line) tells the shell which interpreter to use to run the rest of the script’s contents:

#!/usr/local/bin/perl

Or, to avoid compatibility issues on systems that might have Perl installed in a different location, a more portable interpreter line would be as follows:

#!/usr/bin/env 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/env perl $string = "Hello world!"; $hostname = `hostname`; ...

Get FreeBSD6 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.