Questions tagged [getopt-long]

Getopt::Long is a command line switch parsing library for Perl. For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options.

The Getopt::Long Perl module is a parser for the POSIX command line switch syntax with GNU extensions. Both the traditional -s single character switches and the longer --longer switches are supported.

For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options. For details, please see here.

190 questions
2
votes
1 answer

C programming with getopt(): giving command line flags criteria

I am beginning to teach myself C. I have run into a few bumps here and there but right now I am stumped by getOpt(). The main thing thats giving me trouble is when I try to make certain flags dependent on other flags. For example I want these to…
sudobangbang
  • 1,406
  • 10
  • 32
  • 55
2
votes
3 answers

How can I handle -r= with Perl's Getopt::Long?

I am parsing command line options in Perl using Getopt::Long. I am forced to use prefix - (one dash) for short commands (-s) and -- (double dash) for long commands (e.g., --input=file). My problem is that there is one special option (-r=)…
Jay Gridley
  • 713
  • 2
  • 12
  • 33
2
votes
1 answer

How do I fix Perl Getopt::Long event not found error?

I am using Getpt::Long to take the arguments from the command line and assign them to their respective variables. But, I am getting errors when I am printing it. The code and the error is as follows: #!usr/bin/perl use strict; use warnings; use…
deep
  • 686
  • 4
  • 17
  • 33
2
votes
2 answers

python get opt long option only

I want to use getopt to get input from command line argument with long option only Example: ./script --empid 123 options, args = getopt.getopt(sys.argv[1:],['empid=']) for opt, arg in options: print 'opts',opt if opt in…
user2763829
  • 793
  • 3
  • 10
  • 20
2
votes
1 answer

getopt_long() doesn't see terminator

I'm working on a C program which uses getopt to read options, then iterates through the remainder of argc to read the non-optional arguments. Some of those non-optional arguments are numbers, some of which are negative. Common problem, I know, and…
Frank Harris
  • 305
  • 1
  • 6
  • 16
2
votes
2 answers

Recognize unknown options in Getopt::Long

How can you recognize unknown options using Getopt::Long? I tried <>, but it did not work as expected. Consider: use Modern::Perl; use Getopt::Long; my $help=''; GetOptions ('help' => \$help,'<>' => \&usage); usage() if $help; usage() if @ARGV !=…
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
2
votes
3 answers

How to explain GetOptions usage?

I have a script which takes 3 input variables from CLI and insert it to 3 variables respectively: GetOptions("old_path=s" => \$old_path, "var=s" => \$var, "new_path=s" => \$new_path, "log_path=s" => \$log_path) or die…
deep
  • 686
  • 4
  • 17
  • 33
2
votes
1 answer

Perl GetOptions strange comma in one of the options

use Getopt::Long::Configure(pass_through); # .... GetOptions( "display=s" => \$display, "input=s", => \$input, # A strange comma right after "input=s", ); Can some one explain this Perl code above for me? The second option…
lxw
  • 91
  • 1
  • 6
2
votes
1 answer

How do I send a value that starts with a dash to Getopt::Long?

I've got a client-side script I'm making that communicates with GNU-FTP. I want to be able to send it a custom argument on the command line, so I've created an argument --ftp-args This is what it looks like GetOptions( .. redacted stuff.. …
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
2
votes
2 answers

How can I make Perl's Getopt::Long not process a literal = in a parameter name?

I wrote a Perl program "transfer.pl" and the input parameter is the hash value (the key and the value are strings). The code segment is: my %transfers = (); if (!GetOptions("transfer=s" => \%transfers)) { Usage(); exit(1); } I used the…
Larry
1
vote
2 answers

How can i handle arguments in c with getopt_long

i don't really understand how can i correctly handle command line arguments in c using getopt_long function, i create this code : #include #include #include int main(int argc, char** argv) { int next_option; …
funnyCoder
  • 787
  • 2
  • 10
  • 30
1
vote
2 answers

Making Perl Getopt::Long keep the backslash ( \ ) in a string

One of my colleagues wrote a perl script that asks for the user's windows domain/user name, which of course we enter the the following format domainname\username. The Getopt:Long module then converts this into a string dropping out the '\' character…
1
vote
1 answer

Negatable options in perl

I have a negatable option defined as top!. When a command uses this option, say : command_name -top, prints a warning to the user Code snippet for it is as follows : if ($args{top}) { print "Warning"; } But, when a command uses a negated option,…
Dhanashri P
  • 111
  • 5
1
vote
2 answers

GetOptions missing parameter value is not check

Is there any way to check my input (value) is provided or not when using GetOptions? #file testing.pl #!/usr/5.14.1/bin/perl use strict; use Getopt::Long qw(:config no_ignore_case…
Archmal
  • 63
  • 1
  • 8
1
vote
1 answer

Can I bind two different input flags using Getopt::Long lib in perl?

Lets take a simple example: I wanto to have the following input in my script: [ {foo => date_1}, {foo2=> date_2}, {foo3=> undef}, # there was no input ... # probably more in the future ] So using something similar to this: use strict; use…
nck
  • 1,673
  • 16
  • 40