Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: longest common substring... almost?

by kvale (Monsignor)
on Apr 18, 2004 at 18:06 UTC ( [id://346133]=note: print w/replies, xml ) Need Help??


in reply to longest common substring... almost?

Text::Abbrev, a core module, can do what you want:
use Text::Abbrev; chomp(my @a = <DATA>); s/\s/_/g foreach @a; my %hash = abbrev @a; print "$_ $hash{$_}\n" foreach sort keys %hash; __DATA__ RPL AUSTRIA AR REPORTING RPL AUSTRIA AR REV ACCT
This yields
RPL_AUSTRIA_AR_REP RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPO RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPOR RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPORT RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPORTI RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPORTIN RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REPORTING RPL_AUSTRIA_AR_REV RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_ RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_A RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_AC RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_ACC RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_ACCT RPL_AUSTRIA_AR_REV_ACCT
the set of all possible unique abbreviations of your list of words, which is frequently what one wants. If you want just the shortest abbrev, pick the first member for each value from the sorted list above. The underscores are for readablility, you can drop them.

-Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://346133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-29 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found