Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Peruse my code...

by Arien (Pilgrim)
on Aug 31, 2002 at 17:33 UTC ( [id://194358]=note: print w/replies, xml ) Need Help??


in reply to Re: Peruse my code...
in thread Peruse my code...

Also some Regexps are broken or inefficient.

my %spec = ( username => qr#^[A-Za-z][-.\w]{2,29}$#, domain => qr#^(a|c|f|h|ho|i|k|o|s|x)\.com$#, email => qr#^[\w\.\-]+\@(?:[a-z\d\-]+\.)+[a-z\d]+$#i, service => qr#^Yes|No$#, conditions => qr#^Yes$#, );

These regexes allow for a newline after the last character. This could lead to trouble, for example when assuming your log file consists of one line with fields seperated by commas (as one probably would).

The regex for domains assumes all domains are .com, which they are not. Apart from that, it can be written in a more efficient way.

Your service regex is flawed: it allows for any string as long as it starts with Yes or ends with No (and optional newline).

Also, there's no need to escape a dash (like you do in the email regex) if you put it at the beginning or end of a character class.

In summary, I'd write those as:

my %spec = ( username => qr/^ [A-Za-z] [-.\w]{2,29} \z/x, domain => qr/ ^h\.net\z | ^(?:ho | [acfikosx])\.com)\z /x, email => qr/^ [\w\.-]+ \@ (?:[a-z\d-]+\.)+ [a-z\d]+ \z/ix, service => qr/^(?:Yes|No)\z/, conditions => qr/^Yes\z/, );

— Arien

Replies are listed 'Best First'.
Re: Re: Re: Peruse my code...
by fruiture (Curate) on Sep 01, 2002 at 09:48 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://194358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2025-02-09 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.