in reply to convert string of chars and numerics to a numeric value
use strict; use warnings; my @strs = qw{smpl95 smpd9 fuj324}; foreach my $str ( @strs ) { print qq{Original: $str\n}; my $numStr = there($str); print qq{Numified: $numStr\n}; my $decoded = backAgain($numStr); print qq{ Decoded: $decoded\n}; print q{-} x 25, qq{\n}; } sub there { my $str = shift; my $numStr; $numStr .= sprintf q{%03d}, ord for split m{}, $str; return $numStr; } sub backAgain { my $numStr = shift; (my $str = $numStr) =~ s{(...)}{chr $1}eg; return $str; }
Here's the output.
Original: smpl95 Numified: 115109112108057053 Decoded: smpl95 ------------------------- Original: smpd9 Numified: 115109112100057 Decoded: smpd9 ------------------------- Original: fuj324 Numified: 102117106051050052 Decoded: fuj324 -------------------------
I don't know if this is anywhere near what you are looking for. Perhaps you could clarify you question?
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: convert string of chars and numerics to a numeric value
by js1 (Monk) on Apr 20, 2007 at 12:02 UTC | |
by johngg (Canon) on Apr 20, 2007 at 13:21 UTC |