Click to See Complete Forum and Search --> : Passing a javascript 'escaped()' string


Nedals
04-17-2003, 09:06 PM
I'm passing a javascript 'escaped()' string to a CGI script via the QUERY_STRING.
This works as long as I don't use 'strict' but when I do I get this error

....can't use global $1

$ENV{'QUERY_STRING'} = "n%26d+a%20l%24"; # test result to be "n&d+a l$"
my $data = $ENV{'QUERY_STRING'};
my $data =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C',hex($1))/eg;
print "$data\n";

Is there a simple soultion?

jeffmott
04-18-2003, 12:10 AM
You are declaring $data with my twice.

And just a note to simplify the regex. Since you know the two characters following a % are hex digits, there's no reason for the character classes, and pack('C', ...) can be more simply replaced with chr.$data =~ s/%(..)/chr hex $1/eg;

Nedals
04-18-2003, 12:31 AM
Dah!!! :o
And thanks for the tip on the simplification