#!/usr/bin/perl -sw
use strict;
use warnings;
use Getopt::Long;
my $remote = 0;
my $test = 0;
GetOptions ('remote' => \$remote, 'test' => \$test);
print "$remote:$test\n";
perl test.pl –remote –test
The above prints “0:0”. I am new to Perl so I have been unable to determine why this isn’t working.
I also ran the “Simple Options” section from http://perldoc.perl.org/Getopt/Long.html#Simple-options and that didn’t produce anything either.
I believe the
-scommand line option you include on your she-bang line is biting you. According to the perlrun documentation, the-scommand line option:If you remove that option, things should work as you expect. I would also recommend removing the
-wsince you are already using theuse warningsdirective (theuse warningsdirective is much more fully featured, essentially replacing the-woption).So, long story short, make your first line: