If anyone can point me towards some resources or provide me with an answer to the following I would greatly appreciate.
I have this code. The purpose is to take Input either in a text file or an Ip address range. A synopsis of the code in question:
use strict;
use Getopt::Long;
my $Input_File=0;
my $Ip_Range=0;
GetOptions('InputFile|i=s' => \$Input_File
'Ip|I=s' => \$Ip_Range);
if ($Input_File xor $Ip_Range)
{
# We have one or other of the input options given in the command line.
}
else
{
no valid input print usage.
}
My question is :
Am I missing a way for Getopt::Long to take care of the conditional I wrote. Some way or requiring an option to be passed or even better if no option is passed for the script to use
ARGV[0] as the input file.
For example
script.pl i input.txt
script.pl I 10.1.1.1-10.1.1.254
script.pl input.txt
should all be valid.
With the code above I can resolve the first two.
I have been searching for examples and am missing something very obvious I know.
I know I can add an elseif to catch the third case but it seems Getopt::Long should handle this and I am misreading it.
Thank you
Note Updated bad logic in the conditional and missing ; and reminds one self cut and paste don't retype.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.