• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

How to eliminate the need for option name for the command line arguments to be parsed in Perl

Hi,
I use the following code to parse the options:

GetOptions ( 
				'f|file=s' => \$files_in_job
				)
				or die "Error parsing arguments\n";

Open in new window


This code requires -f or -file before the argument.

How can I make it that does not require anything before the argument?

I tried something like the following but it does not work:

GetOptions ( 
				'' => \$files_in_job
				)
				or die "Error parsing arguments\n";

Open in new window

0
Tolgar
Asked:
Tolgar
1 Solution
 
wilcoxonCommented:
If -f[ile] is the only options then simply remove GetOptions and use this:
my $file = shift;
die "invalid file: $file" unless (-f $file);

Open in new window


If it allows multiple files (haven't used GetOptions in a long time) then this is equivalent:
my @files = @ARGV;
foreach my $fil (@files) {
    die "invalid file: $fil" unless (-f $fil);
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now