A Whirlwind Tour of Perl
So, you want to see a real Perl program with some meat? (If you don’t, just play along for now.) Here you are:
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines) {
s/\w<([^>]+)>/\U$1/g;
print;
}Now, the first time you see Perl code like this, it can seem pretty strange. (In fact, every time you see Perl code like this, it can seem pretty strange.) But let’s take it line by line, and see what this example does. (These explanations are very brief; this is a whirlwind tour, after all. We’ll see all of this program’s features in more detail during the rest of this book. You’re not really supposed to understand the whole thing until later.)
The first line is the #! line,
as you saw before. You might need to change that line for your system,
as we discussed earlier.
The second line runs an external command, named within backquotes (`
`). (The backquote key is often found next to the number 1 on
full-sized American keyboards. Be sure not to confuse the backquote with
the single quote, '.) The command we
used is perldoc -u -f atan2; try typing that at
your command line to see what its output looks like. The
perldoc command is used on most systems to read and display the
documentation for Perl and its associated extensions and utilities, so
it should normally be available.[*] This command tells you something about the trigonometric
function atan2; we’re using it here
just as an example of an external command whose output we wish to
process.
The output of ...