I've inherited the following Perl code, and I'm having difficulty understanding what exactly the index and match functions are doing here:
my $url = $ENV{'REQUEST_URI'};
my $loc = $url;
$loc =~ s/\/parks\///i;
my $page = substr($loc, 0, index $loc, "_");
I know that index(str, char) returns the index of a particular character, so what function does index $loc serve? Is it simply returning the length?
I'm also confused by the line $loc =~ s/\/parks\///i; which matches the phrase "/parks/" in the url. I don't see the purpose of it, because whether it returns true or false, isn't $loc still a string containing the url? What should I expect to be contained in $page?
I am very new to Perl so I appreciate that there will be some nuances that I haven't yet grasped.