Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Can you spot the problem?

by hardburn (Abbot)
on Mar 05, 2004 at 15:45 UTC ( #334250=note: print w/ replies, xml ) Need Help??


in reply to Re: Can you spot the problem?
in thread Can you spot the problem?

Don't parse IP addresses with regexen in real code. The OP makes an amusing puzzle (one which I have admittedly not figured out yet), but nothing more. There are far more valid formats for IPv4 than the traditional dotted-quad one. I don't even want to think about all the formats available for IPv6.

Look at Valid IP? for more info.

----
: () { :|:& };:

Note: All code is untested, unless otherwise stated


Comment on Re: Re: Can you spot the problem?
Download Code
Re: Re: Re: Can you spot the problem?
by ambrus (Abbot) on Mar 05, 2004 at 21:28 UTC

    You can match an IP-address with a regexp, just don't try to roll your own, do  {use Regexp::Common; /$RE{net}{IPv4}/} instead.

      From the Regexp::Common::net docs:

      $RE{net}{IPv4}

      Returns a pattern that matches a valid IP address in "dotted decimal"

      So it only matches the traditional dotted-quad form of IPv4 addresses. That's just one format IPv4 can come in (albeit the most common). There are modifiers Regexp::Common allows for some other formats (like "dotted hex"), but not all possible formats (a simple 32-bit number, for example).

      ----
      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

        There are modifiers Regexp::Common allows for some other formats (like "dotted hex"), but not all possible formats (a simple 32-bit number, for example).
        Yeah, it's true that IP addresses can be given as a 32-bit number, and while I've encountered such IP addresses many times, it's always as data in a program, or binary data between programs. I've never found myself parsing 32 bit numbers out of a file, to get the IP address.

        Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-08-23 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls