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?
$domain = "domainname.co.uk";
$root = "public_html";
$webpage = "domainname.co.uk/foo/bar/foobar.html";
my $string = ($webpage =~ s/^$domain//g);
print $string."\n";
Remove the $string
and just do $webpage =~ s/^$domain//g;
and then do the string concatenation with $webpage
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With