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

Re: [FWP] ip address golf-eek!



In article <Pine.LNX.4.21.0005081045130.1450-100000@dream.chello.nl>,
Arjen Wiersma <arjen@wiersma.org> wrote:
> Again...
> 
> for(split/\./,$_,4){$x++ if(/^\d{1,3}$/&$_<256)}

This one validates "1\n.12\n.123\n.123\n" which it probly didna oughta.
Also, $x is not lexical or zeroed, so it will just work the first time
through this code.

Something like this gets it all in one expression:

do{my$x;for(split/\./,$_,4){$x++if/^\d{1,3}\z/&$_<256};$x==4}

To guard against $*, the ^ would also need to be changed to \A.

Yuck.

Here's a splightly different approach:

$_ eq join'.',map$_>255^$_,split/\./,$_,4

but it's not -w clean.
(Neither is the suggestion above, unless & is changed to &&).

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