On 27/05/2013 23:55, shawn wilson wrote:
On May 27, 2013 1:02 PM, "Dr.Ruud" <rvtol+use...@isolution.nl <mailto:rvtol%2buse...@isolution.nl>> wrote: > On 26/05/2013 14:40, shawn wilson wrote:
>> Thank y'all, I got to where I want to be: >> https://github.com/ag4ve/geocidr > > > ... > > or grep { ! m%[0-9\.\/]+% } @{$opts->{ip}} > > or scalar(@{$opts->{ip}}) < 1 > > The '+' in the regexp is superfluous as-is. > (your regexp isn't anchored) > > > You probably meant it more like: > > ... > or !@{$opts->{ip}} > or grep m{[^0-9./]}, @{$opts->{ip}} > You don't want to grep for anything that isn't a number there.
Who is this 'You'? You clearly misunderstand m{[^0-9./]}.
I like the !@arr vs my scalar though. And... You're right on anchoring - I should. But as I'm lastly matching for an IP (with a possible subnet, it should probably be more like: m(^[0-9\./]+$) Or better: m(^[0-9\.]+(?:/(?:[0-3])?[0-9])?$) Or more better: m(^(?:(?:[0-2])?[0-9]{1,2}\.){3}(?:[0-2])?[0-9]{1,2}(?:/(?:[0-3])?[0-9])?$)
There are many much clearer ways to do that, And be aware of octalness.
I know there are some edge cases like 256 octets and 32 bit subnets but that's my 'good enough' IP matching regex (written from a phone, in bed because I'm too lazy to get up and masochistic enough to do it so I hope I didn't error any). I'll make this part better and get ip6 in here.
Just be properly lazy, and check Regexp::Common, Regexp::IPv6. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/