David Eason wrote:
>
> Is there a better way to say:
>
> my @input_files = glob (join " ", @ARGV) unless $#ARGV = -1;
> foreach my $doc ( @input_files ) { ... __code goes here___ }
>
> I put the unless clause in there because otherwise...
> if there are no file arguments, @input_files ends up having an element [0]
> And the foreach loop tries to run anyway.
That will break if there are any file names with whitespace in them.
$ perl -le'
@ARGV = ( "file one.txt", "file two.txt", "0" );
my @input_files = glob (join " ", @ARGV) unless $#ARGV == -1;
print "Number of files: " . @input_files;
'
Number of files: 5
Better to do it this way instead:
$ perl -le'
@ARGV = ( "file one.txt", "file two.txt", "0" );
my @input_files = @ARGV;
$_ = glob for @input_files;
print "Number of files: " . @input_files;
'
Number of files: 3
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]