Subject: | Getopt-ArgvFile1.11 Does not Allow STDIN as an fileOption File |
Getopt::ArgvFile does not allow STDIN to be used to pass in command line
arguments.
Given the following program (foobarbaz.pl, attached):
#! /usr/bin/perl
use strict;
use Getopt::ArgvFile default => 1;
use Getopt::Long;
my $foo = 0;
my $bar = 0;
my $baz = 0;
GetOptions(
'foo' => \$foo,
'bar' => \$bar,
'baz' => \$baz,
) or die "failed command line parsing!n";
print "\n";
print "\$foo is " . ($foo ? "SET" : "NOT SET") . "\n";
print "\$bar is " . ($bar ? "SET" : "NOT SET") . "\n";
print "\$baz is " . ($baz ? "SET" : "NOT SET") . "\n";
print "\n";
print "Here is the rest of \@ARGV:\n";
foreach my $value (@ARGV) {
print "---> $value\n";
}
print "\n";
exit;
and the following options text file (foobarbaz.txt, also attached):
--baz
farkle
purple nurple
When run as follows:
foobarbaz.pl @foobarbaz.txt
the process produces:
$foo is NOT SET
$bar is NOT SET
$baz is SET
Here is the rest of @ARGV:
---> farkle
---> purple
---> nurple
which is what is expected.
However, when run as follows:
foobarbaz.pl @- < foobarbaz.txt
the process produces:
$foo is NOT SET
$bar is NOT SET
$baz is NOT SET
Here is the rest of @ARGV:
which is not expected.
I generated these results on an openSUSE 10.2 system, running perl
5.10.0 and the 1.11 version of Getopt::ArgvFile. I have also experienced
the above on an openSUSE 11.2 system, running perl 5.10.0 with the 1.11
version of Getopt::ArgvFile.
Performing some debugging, I isolated the code line causing the issue
and fixed it. The changes necessary to resolve the bug are in the
attached patch.txt file.
If this is not a true bug, please consider the above patch as an
enhancement. I have a need to be able to pass commandline arguments into
a perl program via STDIN, and this module is the most viable way of
doing it, short of writing my own.
Subject: | foobarbaz.txt |
--baz
farkle
purple nurple
Subject: | patch.txt |
--- /usr/lib/perl5/site_perl/5.10.0/Getopt/ArgvFile.pm 2007-04-21 14:26:47.000000000 -0400
+++ Getopt/ArgvFile.pm 2010-05-19 19:56:28.000000000 -0400
@@ -756,7 +756,7 @@
push(@c, $arrayRef->[$i]), next if $arrayRef->[$i]=~s/^$prefix/$maskString/;
# skip nonexistent or recursively nested files
- next if !-e $arrayRef->[$i] || -d _ || $rfiles{$casesensitiveFilenames ? $arrayRef->[$i] : lc($arrayRef->[$i])};
+ next if (($arrayRef->[$i] ne '-') && (!-e $arrayRef->[$i] || -d _ || $rfiles{$casesensitiveFilenames ? $arrayRef->[$i] : lc($arrayRef->[$i])}));
# store filename to avoid recursion
$rfiles{$casesensitiveFilenames ? $arrayRef->[$i] : lc($arrayRef->[$i])}=1;
Subject: | foobarbaz.pl |
#! /usr/bin/perl
use strict;
use Getopt::ArgvFile default => 1;
use Getopt::Long;
my $foo = 0;
my $bar = 0;
my $baz = 0;
GetOptions(
'foo' => \$foo,
'bar' => \$bar,
'baz' => \$baz,
) or die "failed command line parsing!n";
print "\n";
print "\$foo is " . ($foo ? "SET" : "NOT SET") . "\n";
print "\$bar is " . ($bar ? "SET" : "NOT SET") . "\n";
print "\$baz is " . ($baz ? "SET" : "NOT SET") . "\n";
print "\n";
print "Here is the rest of \@ARGV:\n";
foreach my $value (@ARGV) {
print "---> $value\n";
}
print "\n";
exit;