Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to give an IP value as an option,if I give the IP as 'i' or 's',I am getting an error.Can anyone advise how can pass an IP(for example 10.34.34.456)

GetOptions (\%options, 'IP=i')

Replies are listed 'Best First'.
Re: Get options query
by wind (Priest) on Apr 29, 2011 at 04:00 UTC

    From Getopt::Long:

    use Getopt::Long; GetOptions( 'ip=s' => \my $ip, ); print $ip;
    Note, pass your parameter like one of the following:
    perl yourscript.pl --ip=192.168.0.1 perl yourscript.pl --ip 192.168.0.1
Re: Get options query
by toolic (Bishop) on Apr 29, 2011 at 12:37 UTC
    You should show the error message you are getting, as well as the exact command line you are using.

    I have no problem when I use 's' to denote a string (Getopt::Long):

    use warnings; use strict; use Getopt::Long; my %options; GetOptions (\%options, 'IP=s'); print "$options{IP}\n" if exists $options{IP};

    Here are some sample command lines:

    $ 901916.pl $ $ 901916.pl -IP 10.34.34.456 10.34.34.456 $ $ 901916.pl -ip 10.34.34.456 10.34.34.456 $ $ 901916.pl -I 10.34.34.456 10.34.34.456 $