Actually, I think I'd prefer not using Getopt::Long (or even Getopt::Std) at all: just expect one argument after the name of the script. If it turns out to be the name of an existing file, read that file; if it's not a file, but it looks like an IP range, treat it as such; otherwise die with a usage message:
use strict;
my $Usage = "$0 lower.ip.addr-upper.ip.addr\n or\n$0 text.file\n";
die $Usage unless @ARGV == 1;
my ($iplower, $ipupper);
if ( -f $ARGV[0] ) {
# treat the arg as a file
}
elsif ( $ARGV[0] =~ /^((?:\d{1,3}\.){3}\d{1,3})-(\d{1,3}(?:\.\d{1,3}){
+3})$/ ) {
($iplower,$ipupper) = ($1,$2);
}
else {
die "Invalid command-line arg: $ARGV[0]\n\n$Usage";
}
...
(update: I do not mean to suggest that I'd
never use of the Getopt modules -- I do use them often. It's just that for a simple case like this, option flags seem unnecessary: you have to provide one type of arg or the other, and you can't provide both -- these are not really "options", and you don't need a command-line flag to tell them apart.)
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.