msk_0984 has asked for the wisdom of the Perl Monks concerning the following question:
I have problem with the regular expression while using the substitution operator.
Prints the output as$str1 = "accessagain"; $str2 = "@cce$$ag@!n"; $abc1 = "accessagain"; $abc2 = '@cce$$ag@!n'; $str1 =~ s/$str1/$str2/ ; $abc1 =~ s/$abc1/$abc2/ ; print " New String : $str1 : $abc1 \n";
The problem is that when I have special characters in the variable and try to substitute the variable it is getting interpolated and thinking it as a perl variable.=> 18203@!n : @cce$$@g@!n
I need to escape the special characters in the variable and it should be replaced. Actually my main requirement is that I am storing user passwords in a file for a small web-application in encrypted format.
When the user needs to update his password and use some special characters in it. The record is not getting updated since I am using the same above logic i.e the substitution operator to replace the existing record with the new record.
Is there any way to escape the special characters in the variable.
Please help me out in this regard. Thanks In Advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Escape the special characters while substitution
by ikegami (Patriarch) on Apr 24, 2009 at 18:35 UTC | |
by MidLifeXis (Monsignor) on Apr 24, 2009 at 19:12 UTC | |
by bichonfrise74 (Vicar) on Apr 24, 2009 at 19:45 UTC | |
|
Re: Escape the special characters while substitution
by almut (Canon) on Apr 24, 2009 at 18:30 UTC |