Bootstrap FreeKB - Perl (Scripting) - Escape literal dollar sign $
Perl (Scripting) - Escape literal dollar sign $

Updated:   |  Perl (Scripting) articles

Let's say you have the following Perl script which prompts a user for input.

#!/usr/bin/perl
use strict;
use warnings;

print "password: ";
my $password = <STDIN>;
chomp $password;

 

Running this script will produce the prompt. Let's say the use enters a value that contains the dollar sign $ character.

~]# perl example.pl
password: its$secret

 

At this point, the $password variable will contain the dollar sign character. For example, here is how you can output the value of the $password variable.

print "password = $password \n";

 

Which should output the following.

password = its$secret

 

Here is how you could update the $password variable so that the dollar sign character is escaped.

$password = s|\$|\\\$|g;

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b7d6bd in the box below so that we can be sure you are a human.