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

Re: [MacPerl] matching a $



David Ackerman, <dackerm@fas.harvard.edu> wrote:

>You might also try:
>
>if (($fName =~ /^([^\d\s]+)$/) &&
>   ($lName =~ /^([^\d\s]+)$/)) {
>
>which eliminates an alternation.

And also misses my point(s).  I specified the alternation not because it 
was strictly necessary, but to show that there were two DISTINCT possible 
error states to check for. We want to exclude values containing ONLY runs 
of spaces OR any combination including at least one digit. This is 
DIFFERENT from Gene's original intent.  I wanted to show this as clearly 
as possible. We want to be careful NOT to exclude valid names which 
INCLUDE a space or a dash in them.  Gene's *intended* test wasn't robust 
enough to stand up to real-world use.

"Karl Maria Fredrich Ernst von Weber" would have a hard time using Gene's 
form had it worked as he intended. 

This is becoming largely a moot argument over semantics at this point, 
but here goes: There's nothing to gain by eliminating a single 
alternation, except maybe a prize in an obsfucated Perl contest. The 
point of the alternation is visually clear to anyone who knows Perl. The 
alternation is also terser.  If there were more than say, three or four 
alternatives (in fact, at greater than five alternatives I'd say do it 
your way!), I could see using your approach.

You're jumping through a lot of hoops just to avoid using "|" once. 
You've increased the verbosity of the regex by 25%.  IMHO, what you're 
doing is semmantically unclear.  Not wrong, mind you, and even useful in 
the right setting, but not straightforward and obvious, which is what one 
needs when giving helpful instruction.

--B

# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org