die("Usage: $0 [-c] [-v] <-f pattern-file | subnet/netmask> file [file +...]\n") unless ( (defined $#ARGV && $#ARGV > -1) || (defined $opt_f +) ) ; ... if ( defined $#ARGV && $#ARGV > -1) {

The variable $#ARGV is ALWAYS defined!    You probably want something like this instead:

die "Usage: $0 [-c] [-v] <-f pattern-file | subnet/netmask> file [file +...]\n" unless @ARGV || defined $opt_f; ... if ( @ARGV ) {


# remove non-ip-address characters, trim, break into words + to validate $IP_LINE =~ s/[^0-9.]+/ /g ; $IP_LINE =~ s/^ // ; $IP_LINE =~ s/ $// ; my @WORDS = split(/\s+/,$IP_LINE) ;

Would be better as:

# remove non-ip-address characters, trim, break into words + to validate $IP_LINE =~ tr/0-9./ /c; my @WORDS = split ' ', $IP_LINE;


# grep each file for my $FNAME (@ARGV) { if ( ! -r $FNAME ) { printf STDERR "Cannot read: $FNAME\n" ; next ; } open ($INFILE, "<$FNAME") ;

You have the possibility of a race condition where the file could become non-readable after the -r test.    You should print the error message only if open fails and include the $! variable so you know why it fails.

# grep each file for my $FNAME (@ARGV) { open my $INFILE, '<', $FNAME or do { warn "Cannot open '$FNAME' because: $!"; next; };

In reply to Re: Looking for feedback on a script by jwkrahn
in thread Looking for feedback on a script by systemj

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.