[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] ip address golf-eek!



On Mon, 8 May 2000, Yitzchak Scott-Thoennes wrote:

sthoen> > $_ eq join'.',map$_>255^$_,split/\./,$_,4
sthoen> 
sthoen> It also rejects leading zeros (e.g. "012.3.4.5") which may or may not
sthoen> be a good idea.

Leading 0s in an IP address technically indicate octal notation for that
particular octet, ie:

	012.0xF.4.5 == 10.15.4.5 

This is the standard behaviour of BIND code, but shouldn't really be
acceptable in parsing IP addresses.  If you accept that, then you should
also be considering '3232235813' ( 192.168.1.37 ) as a valid IP number ;)

I like Holger's, with extra '^$' matches of course:

/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ && !((1 | $1 | $2 | $3 | $4) & ~255

--==--
Bruce.



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe