hi! I hope I understand the problem correctly, i.e. `how to escape'?
In this case I always prefer: our %ESCMAP = (); for ( 0 .. 255 ) { $ESCMAP{ chr( $_ ) } = sprintf("%%%02X", $_); } sub web_escape { my $text = shift; $text =~ s/([^A-Za-z0-9_.-])/$ESCMAP{$1}/g; return $text; } which I've also seen in one library but I don't remember where (CGI.pm, LWP?) anyway... of cource the usual is: sub usual_escape { my $text = shift; $text =~ s/([^A-Za-z0-9_.-])/sprintf("%%%02X", ord($1))/ge; return $text; } I did few benchmarks. The results were: (for 1_000_000 iterations over ~20 char string) web_escape: 18 sec usual_escape: 22 sec escape (from the previous message, i.e. below): ~70 sec P! Vladi. On Fri, 15 Nov 2002 09:42:08 -0600 [EMAIL PROTECTED] wrote: > Improvements? Did somebody mention improvements?? > > Andy Bach, Sys. Mangler > Internet: [EMAIL PROTECTED] > VOICE: (608) 261-5738 FAX 264-5030 > > Programming is a Dark Art, and it will always be. The programmer is > fighting against the two most destructive forces in the universe: entropy > and human stupidity. -Damian Conway, Perl Guru > ----- Forwarded by Andy Bach/WIWB/07/USCOURTS on 11/15/02 09:40 AM ----- > > > saith: "Niels Poppe" <[EMAIL PROTECTED]> > Sent by: [EMAIL PROTECTED] > > > > I figure a lot of people on this list handle UTF-8 and perl :) > > > > What works with URI escaping it? > > > > URI::Escape's &uri_escape fails (miscounts bytes/chars somewhere) > > > > If all else fails, the following does work (on either version of > perl). > > sub escape { > join '', map { > chr($_) =~ /([a-zA-Z0-9_.-])/o? $1 : sprintf "%%%02X", $_ > } unpack 'C*', shift > } > > Any improvements are welcome. > > Niels > > -- Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> Personal home page at http://www.biscom.net/~cade DataMax Ltd. http://www.datamax.bg Too many hopes and dreams won't see the light...
msg02684/pgp00000.pgp
Description: PGP signature