mobiGeek has asked for the wisdom of the Perl Monks concerning the following question:
What I'm looking to do is, given a large list of URLs find the top 31 (chr(1) to chr(31)) most valueable substrings to populate $tnt.my $tnt = [ "http://www." , "https://www." , }; my $implode_url = sub { my ($url) = @_; my $len = scalar(@$tnt); for( my $i = 0 ; $i < $len; $i++) { $url =~ s/$tnt->[$i]/chr($i+1)/eg; # +1 to avoid \0 } return $url; };
Obviously, the most valuable is a measure of the substring's length x frequency within the collection.
So, given a collection of URLs (one per line), does anyone have a suggested algorithm outside of brute force (pseudo-code below)?
Thanks in advance!while( $u = <STDIN> ) { for( $i=1; $i < length($u)-1; $i++ ) { for ($j = 0; $j < length($u)-$i ; $j++ ) { $s = substr($u, $j, $i) $matches($s) += ( $u =~ m/$s/g ); } } # now loop over %matches finding top 30 of: # $matches($key) * length($key) #
mG.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Imploding URLs
by tall_man (Parson) on Jun 09, 2005 at 22:22 UTC | |
Re: Imploding URLs
by shemp (Deacon) on Jun 09, 2005 at 22:37 UTC | |
Re: Imploding URLs
by QM (Parson) on Jun 09, 2005 at 21:12 UTC | |
Re: Imploding URLs
by kscaldef (Pilgrim) on Jun 10, 2005 at 01:12 UTC | |
by mobiGeek (Beadle) on Jun 10, 2005 at 03:01 UTC | |
Re: Imploding URLs
by Cody Pendant (Prior) on Jun 10, 2005 at 00:08 UTC | |
by mobiGeek (Beadle) on Jun 10, 2005 at 02:59 UTC | |
by TilRMan (Friar) on Jun 10, 2005 at 04:44 UTC | |
by mobiGeek (Beadle) on Jun 11, 2005 at 03:54 UTC | |
Re: Imploding URLs
by ank (Scribe) on Jun 11, 2005 at 07:17 UTC | |
by mobiGeek (Beadle) on Jun 12, 2005 at 02:39 UTC | |
Re: Imploding URLs
by dReKurCe (Scribe) on Jun 11, 2005 at 09:33 UTC | |
Re: Imploding URLs
by elwarren (Priest) on Jun 10, 2005 at 22:33 UTC | |
by mobiGeek (Beadle) on Jun 11, 2005 at 03:48 UTC |