----- Original Message ----
> From: Chris Bennett <[email protected]>
> To: [email protected]; [email protected]
> Sent: Sun, April 25, 2010 8:17:07 AM
> Subject: Re: Getting a / when regex should produce nothing
> Is there a better regex for .?\w?\w?
> I want a . letter letter not . letter
> or just two letters etc.
(?:\.\w{2})?
> This regex is to prevent read or write access to
> files up the directory
> tree or non html files. There is also a username
> password for any write
> access.
> undef my $variable is not a common
> idiom but is seen in Programming Perl
> and other places. Is there any reason
> I should use my $variable = undef?
> More typing. :)
What's wrong with just typing "my $variable;"?
> Why was I getting
> a / back? Is that an artifact
> from the perl internals?
In your previous code you didn't check that the pattern
had matched before using $1. In the case when your pattern
doesn't match, $1 remains unchanged from whatever last
set it. There's probably some code earlier on, or internal
to mod-perl, which does a (successful) pattern match that
sets $1 to "/".
The lesson here should be to always check the return value
of your regexps for success, especially when you've used
capture variables in your code like $1-$9.