I took some liberties with your variable and command switch names (too wordy!), i also brought Pod::Usage along for the ride. Hope this helps. :)
use strict; use warnings; use Pod::Usage; use Getopt::Long; our($file,$range,$help); GetOptions( 'file|f=s' => \$file, 'ip|i=s' => \$range, 'help|h' => \$help, ); pod2usage(-verbose=>2) if $help; unless ($file or $range) { $file = shift or pod2usage(-verbose=>1); } if ($file) { open FH, '<', $file or die "can't read $file\n"; chomp($range = <FH>); } print "$range\n"; __END__ =head1 NAME foo.pl - does something with IP range =head1 SYNOPSIS foo.pl [filename] [-file filename] [-ip IPrange] Options: -file -f file to read -ip -i IP range -help -h help message =head1 EXAMPLES Read from file: foo.pl ip.txt foo.pl -f ip.txt foo.pl -file ip.txt Read from STDIN: foo.pl -i 127.0.0.1 foo.pl -ip 127.0.0.1

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: Getopt::Long Validation by jeffa
in thread Getopt::Long Validation by Ninthwave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.