I have the following code:
#$domain = domainname.co.uk
#$root = public_html
#$webpage = domainname.co.uk/foo/bar/foobar.html
my $string = ($webpage =~ s/^$domain//g);
my $linkFromRoot = $dbh->quote($root . $string);
Usualy this works fine but for some reason the output is “public_html 1” instead of “public_html/foo/bar/foobar.html”.
Can anyone see why?
You are not getting the correct answer because the substitution returns you 1 which is the number of items substituted. See perlfaq4‘s answer to How can I count the number of occurrences of a substring within a string?
Remove the
$stringand just do$webpage =~ s/^$domain//g;and then do the string concatenation with$webpage.