> Please help me. I am trying to do pattern matching for an IP address. I have
> tried the following and it does not work:
> unless ( $ip =- /[0-223]\.[0-255]\.[0-255]\.[0-255]/ )
>         {
>                 die ( "Invalid IP\n" );
>         }
> print ( "Valid IP" );
> 
> Is there a way I could actually do this without splitting the IP and working
> on each octect separately?

Validing IP addresses is covered in "Mastering Regular Expressions", Jeffrey
Friedl, O'Reilly.  It covers regular expressions in quite some detail, although
I'd like to see it updated for more modern Perls.

Avoiding regular expressions and using substr is fastest, however it took him
several lines of code.  The reason yours doesn't work is that [0-223] is a
character class the same as [0123]... it won't go from 0 to 223!  Going for
simple is probably best, hence splitting down with 'split' would be a good
beginners approach or when speed isn't critical.  search.cpan.org for modules
that may do this for you!

Jonathan Paton

=====
---------------BEGIN GEEKCODE BLOCK-----------v3.12
GCS/E d+ s+: a20 C++(+++)>$ UHL++>+++ P+++ L++>++++
E- W++(-) N+ o? K- w--- !O M-- !V PS-- PE++ Y++ PGP
t@ 5-- X-- R- tv- b  DI+ D- G++ e h! !r--->++ !y---
----------------END GEEKCODE BLOCK-----------------
JAPH: print`perldoc perlembed`=~/(Ju.*)/,"\n"

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to