Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: (Golf) Expression for matching numeric IP addresses

by BrowserUk (Patriarch)
on Aug 06, 2004 at 18:12 UTC ( [id://380651]=note: print w/replies, xml ) Need Help??

in reply to (Golf) Expression for matching numeric IP addresses

Not a regex, but it works fine for decimal encoded IPs.

sub validIP{ use List::Util qw[ reduce ]; $a = $b; $_[0] =~ m[^[\d\.]+$] and 2**32 > reduce{ $a * 256 + ($b < 256 ? $b : 1e99) } reverse split '\.', $_[0] }

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://380651]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-21 01:52 GMT
Find Nodes?
    Voting Booth?

    No recent polls found