There are a few dubious bits in that code. Why would a URL have a backslash at the end, as suggested by this line:
Code:
$url3 =~ s,(/|\\)$,,i;
You can't have case sensitive and case insensitive slashes either so the "i" modifier is redundant
It might be better written like this:
Code:
my $url = $IN->param('URL');
my $bit = ($url =~ m!(?:http://)?(?:www\.)?(.+)!)[0];
my $chk_dup;
if ($db->count(GT::SQL::Condition->new('URL','LIKE',"$bit%"))) {
$chk_dup = 1;
}
(That regex might be iffy as I rushes a bit).
Regarding the last part....well it's overly lengthy doing 3 checks like this:
Code:
$chk_dup1 ? $chk_dup = $chk_dup1 : '';
$chk_dup2 ? $chk_dup = $chk_dup2 : '';
$chk_dup3 ? $chk_dup = $chk_dup3 : '';
The order is slightly wrong too...it would normally be:
Code:
$chk_dup = $chk_dup1 ? $chk_dup1 : '';
$chk_dup = $chk_dup2 ? $chk_dup2 : '';
$chk_dup = $chk_dup3 ? $chk_dup3 : '';
But even nicer would be:
Code:
$chk_dup = $chk_dup1 || $chk_dup2 || $chk_dup3 || 0;
...but that's all by the by if you use the example above which saves doing 3 queries.