can anyone see any flaws with my code? it works but is it solid?
#!/usr/bin/perl use strict; print cmp_ips('10.1.2.31','10.1.2.30','10.1.2.45')."\n"; print cmp_ips('10.1.2.255','9.1.2.30','11.1.2.45')."\n"; print cmp_ips('10.1.2.255','10.1.1.30','10.1.3.45')."\n"; print cmp_ips('10.1.2.255','10.1.2.30','10.1.2.45')."\n"; print cmp_ips('10.1.2.255','10.1.2.30','10.1.2.255')."\n"; print cmp_ips('10.1.2.30','10.1.2.30','10.1.2.255')."\n"; print cmp_ips('10.1.2.30','10.1.2.30','10.1.2.255')."\n"; sub cmp_ips{ my @r; my @t = quadify(shift); my @s = quadify(shift); my @e = quadify(shift); ($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; return 1 if $t[0]*$t[1]*$t[2]*$t[3] == 1; return 1 if ($r[0] == 0 && ($t[0] >= $s[0] && $t[0] <= $e[0]) ); return 1 if ($r[1] == 0 && ($t[1] >= $s[1] && $t[1] <= $e[1]) ); return 1 if ($r[2] == 0 && ($t[2] >= $s[2] && $t[2] <= $e[2]) ); return 1 if ($r[3] == 0 && ($t[3] >= $s[3] && $t[3] <= $e[3]) ); return 0; } sub quadify{ my $ip = shift; $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; return ($1,$2,$3,$4); }

In reply to 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.