Here's a snippet that I think does what you mean?
# assuming that... my $string = "Perl Monks"; my $n = length($string); my $i = 1; my $result = 0; # here it is. $result += ord($_) * 31^($n-$i++) for split '', $string; ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | +-- String to split | | | | | | +-- split all the charact +ers | | | | | +-- post increment $i | | | | +-- $i is the index | | | +--- $n is the length of $string | | +--- this is the character returned from split | +--- ord() returns the ascii code of the character +--- add what we have to $result
In reply to Re: Generating A Hash Value
by Chady
in thread Generating A Hash Value
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |