I'm trying to write in perl using the GetOptions() method.
This is what I have:
#-- prints usage if no command line parameters are passed or there is an unknown
# parameter or help option is passed
usage() if (
!GetOptions("input:s{,}" => \@inputJarFiles, #at least one
'directory=s' => \$directoryToSearch, #must have a directory to search through
'append=i{0,1}' => \$appendToOutput, #-- optional parameter
'status=i{0,1}' => \$displayStatus, #-- optional parameter
'output=s{0,1}' => \$outputFile, #-- optional parameter
'delimiter=s{0,1}' => \$delimiter) #-- optional parameters
);
sub usage
{
print "Unknown option: @_\n" if ( @_ );
print "usage: SearchForJarInFile [--output OUTPUTFILE] [--status (0|1)] [--delimiter \"delimiter\"] [--append (0|1)] --input FILE(S)|DIR(S) --directory DIR\n";
exit;
}
When I call it from the terminal with this criteria, I have no issue:
SearchForJarInFile.pl --input "..\lib\core.jar" --directory "..\com" --output "./outputOfJars.txt"
But, when I call it like this:
SearchForJarInFile.pl --input "..\lib\core.jar" "..\lib\core2.jar" --directory "..\com" --output "./outputOfJars.txt"
I end up calling the method usage(). What's going on. I thought that the "input:s{,}" took care of having more than one variable. I have also tried:
"input=s{,}"
"input=s@"
Any ideas?
This is what I have:
#-- prints usage if no command line parameters are passed or there is an unknown
# parameter or help option is passed
usage() if (
!GetOptions("input:s{,}" => \@inputJarFiles, #at least one
'directory=s' => \$directoryToSearch, #must have a directory to search through
'append=i{0,1}' => \$appendToOutput, #-- optional parameter
'status=i{0,1}' => \$displayStatus, #-- optional parameter
'output=s{0,1}' => \$outputFile, #-- optional parameter
'delimiter=s{0,1}' => \$delimiter) #-- optional parameters
);
sub usage
{
print "Unknown option: @_\n" if ( @_ );
print "usage: SearchForJarInFile [--output OUTPUTFILE] [--status (0|1)] [--delimiter \"delimiter\"] [--append (0|1)] --input FILE(S)|DIR(S) --directory DIR\n";
exit;
}
When I call it from the terminal with this criteria, I have no issue:
SearchForJarInFile.pl --input "..\lib\core.jar" --directory "..\com" --output "./outputOfJars.txt"
But, when I call it like this:
SearchForJarInFile.pl --input "..\lib\core.jar" "..\lib\core2.jar" --directory "..\com" --output "./outputOfJars.txt"
I end up calling the method usage(). What's going on. I thought that the "input:s{,}" took care of having more than one variable. I have also tried:
"input=s{,}"
"input=s@"
Any ideas?