Working with @ARGV and Script Arguments

One aspect of running Perl scripts that I've sort of sidestepped over the last few days is that of dealing with command-line arguments. Yesterday we talked a bit about Perl's own switches (-e, -w) and so on, but what if you want to actually pass switches or arguments to your own scripts—how do you handle those? That's what we'll discuss in this section: script arguments in general, and handling script switches.

Anatomy of the @ARGV

When you call a Perl script with arguments beyond the name of the script, those arguments are stored in the special global list @ARGV (on the Mac, for droplets, @ARGV will be the filenames that were dropped onto the droplet). You can process this array the same way you would ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.