in reply to (MeowChow) Re: Check IP with support for CIDR
in thread Check IP with support for CIDR

Could not get that to work. However, it did make me think and hence this:
return ( (unpack('N',pack('C4',split(/\./,$i))) ^ unpack('N',pack('C4' +,split(/\./,$1)))) >> (32-$2) ) == 0;
--
TTFN, FNORD

Replies are listed 'Best First'.
(MeowChow) Re3: Check IP with support for CIDR
by MeowChow (Vicar) on Apr 12, 2002 at 08:30 UTC
    My bad, I forgot to negate the result:
    return not unpack ('N', pack ('C4', split /\./, $i) ^ pack ('C4', spli +t /\./, $1)) >> 32 - $2;
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      That works. So I guess you win this round of Golf.
      --
      TTFN, FNORD

      xaphod