#! /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 () { # Do something with the files. print TARGET; print if $debug; } close SRC; } close TARGET