One way to do it would be to split the string into individual characters and sum the ord values for each character. The problem with that is it's easy to get the same answer for different strings. Perhaps you could concatenate the ord values into a string of numbers. This would have the advantage that you could reconstruct the original string from the numbers.

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


In reply to Re: convert string of chars and numerics to a numeric value by johngg
in thread convert string of chars and numerics to a numeric value by js1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.