Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a html doc which converts a string using URIComponent. The href to my perl program is constructed as follows -
$href = "http://mywebsite.com?myperl.cgi?param1="+URIComponent(string) +;
Now, lets say my string is equal to "\u1E02oo", that is a capital B with a dot above followed by two o's, then I should get the following url -

http://mywebsite.com?myperl.cgi?param1=%E1%B8%82

Now I can call param("param1") to obtain my escaped sequence, but then what?

I have a local variable called $compare which I'd like to make a match with. Can anyone suggest how I go about this?

Thanks.
#!/usr/bin/perl -w use strict; $| = 1; use CGI qw/:standard :no_xhtml/; use CGI::Carp "fatalsToBrowser"; use HTML::Template; use List::Util qw[ shuffle ]; use URI::Escape; use DBI; use Encode; my $h = new CGI; my $charset = "utf-8"; #print header(-charset=>$charset), print header(), start_html(-title=>"Unicode"); my $compare = "\x{1E02}oo"; my $param1 = param("param1"); //Encode::_utf8_on($param1); if ($compare eq $param1) { print "match"; } print end_html();

Replies are listed 'Best First'.
Re: Handling params from Javascript's encodeURIComponent function
by Baz (Friar) on Mar 27, 2005 at 20:40 UTC
    This works for me.
    #!/usr/bin/perl -w use strict; $| = 1; use CGI qw/:standard :no_xhtml/; use CGI::Carp "fatalsToBrowser"; use Encode; print header(),start_html(-title=>""); my $name = "\x{1E02}oo"; my $param1 = param("f0"); Encode::_utf8_on($temp); print nice_string($param1),br; if($param1 eq $name) { print "EQUAL",br; } print end_html(); sub nice_string { join("", map { printf("%04X ", $_) } unpack("U*", $_[0])); # unpack Unicode characters }