<snip massive='true' /> 

/^[\w.-]+$/ and !/[^\w.-]/ have one major difference (and I am kicking
myself for not seeing it until now).  The former requires that at least
one character must exist. !/[^\w.-]/ is equivalent to /[^[\w.-]*$/.
However, this can be overcome by saying !(/^$/ or /[^\w.-]/) and it
still has one advantage over /^[\w.-]+$/: the values of $`, $&, and $'
(everything before the match, the match, and everything after the match
respectivly).  This allows the creation of useful messages such as:

if (/^$/ or /[^\w.-]/) {
        print "ilegal character ($&) in:$_\n";
}

or

if (/^$/ or /[^\w.-]/) {
        print "cannot use character ($&) in:$`<b>$&</b>$'\n";
}


--
Today is Prickle-Prickle, the 18th day of Confusion in the YOLD 3167
Kallisti!


Reply via email to