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

Re: [FWP] IP address regex golf



On Apr 29, Rick Delaney said:

>Jeff Pinyan wrote:
>> 
>> >>     do{$1>255||$b++>3and$a=1while/\G(\d+)(\.|$)/g;!$a};
>
>isn't correct since it will return true for random garbage.  But perhaps
>you had something else in mind.

Is was thinking it would useful in my loop -- the only thing I could come
up with was several characters longer:

  do{{$1>255||$a++>3and$a=0&&last while/\G(\d+)(\.|$)/g;$a}};

The point being, something like:

  !( first { $1 > 255 || $a++ > 3 } /\G(\d+)(?:\.|\z)/g );

Which would stop short if given something hideous like

  "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"
           ^ stops there

or

  "256.1.1.1"
   ^^^ stops there

Just an idea.

  !first{$1>255||$a++>3}/\G(\d+)(?:\.|\z)/g;

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy@pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/


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