1. This may be what you want:

    $ perl -le' my %hashIPs = qw( 192.168.1.0 1 192.168.1.1 1 192.168.1.2 1 192.168.1.4 1 192.168.1.5 1 192.168.1.6 1 192.168.1.10 1 192.168.1.11 1 192.168.1.12 1 ); my %check; for my $ip ( keys %hashIPs ) { next unless $ip =~ /^(\d+\.\d+\.\d+)\.(\d+)$/; $check{ $1 } = 0 x 256 unless exists $check{ $1 }; substr $check{ $1 }, $2, 1, 1; } for my $key ( keys %check ) { print "Missing: $key.$-[0] - $key.", $+[0] - 1, "\n" while $check{ $key } =~ /(?<=1)0+(?=1)|^0+|0+$/g; } ' Missing: 192.168.1.3 - 192.168.1.3 Missing: 192.168.1.7 - 192.168.1.9 Missing: 192.168.1.13 - 192.168.1.255
  2. Instead of using grep:

    my @segments = grep {/^(\d{1,3}\.\d{1,3}\.\d{1,3})/} keys %hashIPs;

    You need to use map:

    my @segments = map /^(\d{1,3}\.\d{1,3}\.\d{1,3})/, keys %hashIPs;

In reply to Re: Matching Sequential IP Addresses by jwkrahn
in thread Matching Sequential IP Addresses by Dru

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.