Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
For years I've been using a hash map to store the hex correspondents, and a regex to replace them, but performance is a little crappy for large, say 1MB+, strings. This is what I have now:
# the conversion table
my %table = ( '41' => 'A', '42' => 'B' ...);
# (actually I create it with a one liner,
# but I'll spell it out here for simplicity)
my $input = '4142A0B1'; # usually very large
$input =~ s/(..)/$table{$1}/g; # convert it
print OUTFILE $input; # print converted to file
Any ideas on how to improve this? Using pack or unpack, for instance? The problem is that I can't come up with a good string-to-string unpack sequence.
Barry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert hex to char fast
by BrowserUk (Patriarch) on Mar 30, 2010 at 15:59 UTC | |
|
Re: convert hex to char fast
by ikegami (Patriarch) on Mar 30, 2010 at 16:29 UTC | |
by Anonymous Monk on Mar 30, 2010 at 17:53 UTC | |
|
Re: convert hex to char fast
by almut (Canon) on Mar 30, 2010 at 15:57 UTC |