in reply to Re^2: Using filepath method to identify an .html page
in thread Using filepath method to identify an .html page
OK: How about this:
which yields:$ cat testMD5.pl use strict; foreach my $url(qw@ /index.html /about/time.html @){ hashit($url); } sub hashit { my $url=shift; my @ltrs=split(//,$url); my $hash = 0; foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; } printf "%s: %0.4d\n",$url,$hash }
Keep in mind this is hardly bullet proof. You need to also keep in mind a method to detect hash collisions and and a rehash algorithm.$ perl testMD5.pl /index.html: 1066 /about/time.html: 1547
This brings to mind "the old days" circa 1974 writing assemblers for 8080 microprocessors. Symbol "folding" and hashing.
UPDATE: Limiting yourself to four digits may not be very useful if you have a lot of pages that you are trying to index into your database. The wider your hash is the less likely there will be hash collisions.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Using filepath method to identify an .html page
by Nik (Initiate) on Jan 22, 2013 at 17:11 UTC | |
by blue_cowdawg (Monsignor) on Jan 22, 2013 at 17:33 UTC | |
by Nik (Initiate) on Jan 22, 2013 at 17:48 UTC | |
by blue_cowdawg (Monsignor) on Jan 22, 2013 at 18:13 UTC | |
by Nik (Initiate) on Jan 22, 2013 at 18:19 UTC | |
| |
Re^4: Using filepath method to identify an .html page
by Nik (Initiate) on Jan 22, 2013 at 19:23 UTC | |
by blue_cowdawg (Monsignor) on Jan 22, 2013 at 19:34 UTC |
In Section
Seekers of Perl Wisdom