in reply to How would you do it? Re ARGV, fundamentally!
Modules such as Getopt::Long extract named command line arguments and remove them from @ARGV so that you are able to work with whatever remains in @ARGV. A typical script will use Getopt::Long, extract special parameters, work with what's left. E.g.
#! /usr/bin/perl # # A simple file catenation # # use strict; use warnings; use Getopt::Long; my $target; my $debug; # Get optional args first my $result = GetOptions ("target=s" => \$target, # string "debug" => \$debug); # flag # The target filename is the first filename if it hasn't already been +set. $target = shift @ARGV unless $target; open TARGET, ">$target" or die "unable to open $target [$!]\n"; foreach my $src (@ARGV) { open SRC, "<$src" or die "unable to open $src [$!]\n"; while (<SRC>) { # Do something with the files. print TARGET; print if $debug; } close SRC; } close TARGET
|
|---|