Voting

: max(four, zero)?
(Example: nine)

The Note You're Voting On

abennett at clarku dot edu
18 years ago
I've got a php script that needs to pass a username and password via exec to a perl script. The problem is valid password characters were getting escaped...

Here's a little perl function I wrote to fix it.

sub unescape_string {
my $string = shift;
# all these interpolated regex's are slow, so if there's no
# backslash in the string don't bother with it
# index() is faster then a regex
if ( ! index($string,'\\\\') ) {
return $string;
}
my @characters = ('#', '&', ';', '`', '|', '*', '?', '~', '<', '>', '^', '(', ')',
'[', ']', '{', '}', '$', '\\', ',', ' ', '\x0A', '\xFF' );
my $character;
foreach $character (@characters) {
$character = quotemeta($character);
my $pattern = "\\\\(" . $character . ")";
$string =~ s/$pattern/$1/g;
}
return $string;
}

Hope this is useful.

<< Back to user notes page

To Top