js1 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Is there a straightforward way of converting a string of chars and numerics such as smpl95, smpd9, fuj324 etc.... to a numeric value.
The numeric value could be generated any way, just as long as it returned a number. So for example:
sub str2num{ return hash($str); } $str='smpl95'; $num=str2num($str);
A given string will always return the same value on each call. I'm not worried about being able to reverse the number after, into the same string though.
Cheers,
js1.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: convert string of chars and numerics to a numeric value
by johngg (Canon) on Apr 20, 2007 at 11:11 UTC | |
by js1 (Monk) on Apr 20, 2007 at 12:02 UTC | |
by johngg (Canon) on Apr 20, 2007 at 13:21 UTC | |
Re: convert string of chars and numerics to a numeric value
by GrandFather (Saint) on Apr 20, 2007 at 10:07 UTC | |
Re: convert string of chars and numerics to a numeric value
by andye (Curate) on Apr 20, 2007 at 10:15 UTC | |
Re: convert string of chars and numerics to a numeric value
by swampyankee (Parson) on Apr 23, 2007 at 03:21 UTC |
Back to
Seekers of Perl Wisdom