in reply to RE: RE: form parsing, hex, HTML formatting
in thread form parsing, hex, HTML formatting
This definitely works OK for me.#!/usr/local/bin/perl -w use strict; my $desc = "I %2Blike %3A cheese"; my ($str, @ob); print "TEST: ",test(),"\n";<br> sub test { $_ = $desc; while (/%[0-9A-Za-z]{2}/) { $_ = $&; /[0-9A-Za-z]{2}/; $ob[0] = hex($&); $str = pack("C*", @ob); $desc =~ s/%[0-9A-Za-z]{2}/$str/; $_ = $desc; } return $desc; } returns: TEST: I +like : cheese
I guess the lessons learnt are:... 'myway' => sub { $_ = $str; $name = $str; while (/%[0-9A-Fa-f]{2}/) { $_ = $&; ...
which make a lot more sense.Benchmark: timing 500000 iterations of myway, regexpway... myway: 162 wallclock secs (162.07 usr + 0.00 sys = 162.07 CPU) regexpway: 58 wallclock secs (58.52 usr + 0.01 sys = 58.53 CPU)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: RE: form parsing, hex, HTML formatting
by takshaka (Friar) on May 23, 2000 at 02:12 UTC |