Think this might be a start ? .. only tested on your data: ;))
#!/usr/bin/perl -w
use strict;
sub FindRoot;
my %Word=map {chomp;split /,/} <>;
for (keys %Word)
{
print "Word: $_, etc: $Word{$_}\n";
};
my $Root=FindRoot("Longest",keys %Word);
my @Words=map {split} (values %Word);
my $Word=FindRoot("Shortest",@Words);
print "\n---\n$Root:$Word\n";
for (keys %Word)
{
print "-",substr($_,length$Root),":";
print "",substr($Word{$_},0,rindex($Word{$_},$Word)),"\n";
};
sub FindRoot
{
my $Order=shift;
my %Container;
my $Min="xxxxxxxxxxxxxxx";
print "Finding $Order\n";
if ($Order eq "Shortest")
{
$Min="";
$Min=((length $_)>(length $Min))?$_:$Min for (@_);
}
else { $Min=((length $_)<(length $Min))?$_:$Min for (@_); };
for my $Word (@_)
{
$Container{substr lc $Word,0,$_}++ for(2..length $Min);
};
my $Root="";
$Min=0;
my @List=sort keys %Container;
@List=reverse@List if ($Order eq "Longest");
print "List: @List\n";
for (@List)
{
if ($Container{$_}>$Min)
{
$Root=$_;
$Min=$Container{$_};
};
};
return $Root;
};
It`s probably not the cleanest code, but it was fun to do, so
I thought I`d post it :)))
I figure you can use this as a start to really solve your
problem, it shouldn`t be too hard to once you got the Root,
take the substring out of the hash, and start looking for the next
one (using that FindRoot sub) which would give you `lar` ,
making the next root `BasLar` ...
Hmmmmm... actually I think I got that to work here...
Looking forward to more test-data :))
GreetZ!,
print "profeth still\n" if /bird|devil/;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.