Using filepath method to identify an .html page
Ferrous Cranus
nikos.gr33k at gmail.com
Tue Jan 22 13:26:10 EST 2013
Τη Τρίτη, 22 Ιανουαρίου 2013 6:11:20 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
> On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus <nikos.gr33k at gmail.com> wrote:
>
> > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(
>
>
>
> Either you are deliberately trolling, or you have a major
>
> comprehension problem. Please go back and read, carefully, all the
>
> remarks you've been offered in this thread. Feel free to ask for
>
> clarification of anything that doesn't make sense, but be sure to read
>
> all of it. You are asking something that is fundamentally
>
> impossible[1]. There simply are not enough numbers to go around.
>
>
>
> ChrisA
>
> [1] Well, impossible in decimal. If you work in base 4294967296, you
>
> could do what you want in four "digits".
Fundamentally impossible?
Well....
OK: How about this in Perl:
$ 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
}
which yields:
$ perl testMD5.pl
/index.html: 1066
/about/time.html: 1547
More information about the Python-list
mailing list