Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Generating A Hash Value

by Chady (Priest)
on Jul 03, 2003 at 11:30 UTC ( #271127=note: print w/replies, xml ) Need Help??


in reply to Generating A Hash Value

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

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://271127]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-07-21 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (448 votes). Check out past polls.

    Notices?