Ashok wrote:
> I am having some problem with the substitution operation. This is what
> I am trying to do:
>
> Get a directory path from the user and also the search string in the
> path and remove the string from the path.
>
> Input String: c:\ashok\temp\perl
> Search String: c:\ashok
>
> So the output should be temp\perl.
I suppose you mean \temp\perl - or did I miss a step?
> The Program I wrote looks like this:
>
> $input = <STDIN>;
> $search = <STDIN>;
>
> $input =~ s/$search//;
> print $input;
>
> But this does not work. It looks like there is some confusion with the
> special characters :, \ .
Do not just guess which characters are special in a Perl pattern. Look
it up in "perldoc perlre". There you can also read about how to quote
pattern metacharacters when needed.
> Can somebody tell me what's wrong and how do I fix this?
Besides the unquoted backslash, $search includes an EOL character.
Best fixed with the chomp() function.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl