Alan -
Your problem are the "$" in $path and $url. You need to escape them
somehow or just remove them out of your test script if you don't need
them. Also
if ($url !~ /$path/){
$url = $path.$url;
}
worked fine for me, no need for the m,^, or !.
Mark
Alan Hulley wrote:
>
> Hello. I'm new to Perl and CGI and seem to have dropped in the deep end with this
>particular problem!
>
> The basic requirement is: if a string doesn't begin with a sequence of characters
>then prepend that sequence to the string. Seems simple enough, but this is
>complicated (it would seem from my limited knowledge of Perl) by the fact that both
>strings contain '/' characters).
>
> Here is my code, which attempts to prepend $path to $url if $url doesn't begin with
>$path:
>
> $path = q {//serv12/share_dir$/App Dir/};
> $url = q {//serv12/share_dir$/App Dir/My Dir/My Name/file.htm#20010109};
> $oldurl = $url;
> if ($url !~ m!^$path!)
> {
> $url = "${path}${url}";
> }
> print "path=$path\n";
> print "oldurl=$oldurl\n";
> print "url=$url\n";
>
> When run, the resultant $url is wrong because it originally started with $path and
>$path should not have been prepended to it:
>
> path=//serv12/share_dir$/App Dir/
> oldurl=//serv12/share_dir$/App Dir/My Dir/My Name/file.htm#20010109
> url=//serv12/share_dir$/App Dir///serv12/share_dir$/App Dir/My Dir/My
>Name/file.htm#20010109
>
> I've just read about Leaning Toothpick Syndrome, and I understand that m! etc. is
>used instead of m/ to avoid the problem of
> '/' characters in the pattern, but it hasn't worked above.
>
> Thanks for any replies.
>
> cheers, Alan
>
> --
>
> This e-mail may contain confidential and/or privileged information. If you are not
>the intended recipient (or have received this e-mail in error) please notify the
>sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or
>distribution of the material in this e-mail is strictly forbidden.
--
Mark Murphy
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]