perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bennett <ch...@bennettconstruction.biz>
Subject Re: Getting a / when regex should produce nothing
Date Sun, 25 Apr 2010 17:25:44 GMT
On 04/25/10 08:57, André Warnier wrote:
> Chris Bennett wrote:
> ...
>
>  > $article_file = $q->param("articlefilename") || '';
>
> ok, so suppose it is "12345.html.en"
> ...
>
>> if ($article_file =~ /^([a-zA-Z0-9_-]+\.html.?\w?\w?)$/) {
>> $article_file = $1;
>> } else {
>> $article_file = '';
>> }
>
> ok, matches, so it's still "12345.html.en"
>
>> $article_backup_file = $article_file;
>
> still "12345.html.en"
>
>> $article_backup_file =~ s/\.html$/_backup.html/;
>>
>
> still "12345.html.en"
> (because \.html$ did not match)
>
>
>
I have since changed to:

$article_file = $q->param("articlefilename") || '';
if ($debug) { $error .= qq{<p>A $article_file</p>};}
if ($article_file =~ /^([a-zA-Z0-9_-]+\.html(?:\.\w{2})?)$/) {
	$article_file = $1;
} else {
	$article_file = '';
}
if ($debug) { $error .= qq{<p>B $article_file</p>};}
$article_backup_file = $article_file;
if ($article_backup_file =~ /\.html(?:\.\w{2})?$/) {
	$article_backup_file =~ s/\.html/_backup.html/;
} else {
	$error .= "<p>Please choose an existing File Name ( like y_9-e.html or 
yyy.html.xx ) or use Fill in Template to create a new file.</p>";
}

I think this does the trick.
Please feel free to break this! :)

Mime
View raw message