can anyone see any flaws with my code? it works but is it solid?

You have a precedence problem in this code:

($t[0] == $s[0] && $t[0] == $e[0]) ? $r[0] = 1 : $r[0] = 0; ($t[1] == $s[1] && $t[1] == $e[1]) ? $r[1] = 1 : $r[1] = 0; ($t[2] == $s[2] && $t[2] == $e[2]) ? $r[2] = 1 : $r[2] = 0; ($t[3] == $s[3] && $t[3] == $e[3]) ? $r[3] = 1 : $r[3] = 0;

The  = operator has higher precedence than the  ?: operator.    That should be written as:

$r[0] = $t[0] == $s[0] && $t[0] == $e[0] ? 1 : 0; $r[1] = $t[1] == $s[1] && $t[1] == $e[1] ? 1 : 0; $r[2] = $t[2] == $s[2] && $t[2] == $e[2] ? 1 : 0; $r[3] = $t[3] == $s[3] && $t[3] == $e[3] ? 1 : 0;

However it would be better to use the Socket module that is installed with Perl:

use Socket; sub cmp_ips { my $t = inet_aton( $_[0] ) or do { warn "$_[0] is not a valid IP a +ddress.\n"; return 0 }; my $s = inet_aton( $_[1] ) or do { warn "$_[1] is not a valid IP a +ddress.\n"; return 0 }; my $e = inet_aton( $_[2] ) or do { warn "$_[2] is not a valid IP a +ddress.\n"; return 0 }; return 1 if $t eq $s && $t eq $e; return 1 if $t ge $s && $t le $e && ( $t ne $s || $t ne $e ); return 0; }

In reply to Re: checking ip ranges by jwkrahn
in thread checking ip ranges by arcnon

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.