I need to create an “obscuring” function which replaces a clear-text password in line, before writing it to a log.
It looks like this:
function pass_obscure {
my $logline = shift;
my $pass = "wer32pass$"; # This password is an example. The real one is received as a parameter, or already stored as a global value.
$logline =~ s/$pass/*********/g;
return $logline;
}
But this, of course, doesn’t work. The ‘$’ sign in the password string is interpolated as an endline character, so there’s no match, and so replacement doesn’t work.
How can I resolve this?
(Why not just keep the password out of the log line in the first place?)
Use
quotemeta:Outputs: