Re: best method to perform operations on word lists



Francois Massion schreef:

I have come up with something which seems to work (partially). For my
current purpose it'll do the trick but any suggestion for optimization
is welcome:

(...)
chomp(my $prev = <TERMS>);

my @reducedlist = $prev;

while ( <TERMS> ) {
chomp;
push @reducedlist, $_ unless (/^$prev/ && length ($_)-
length($prev)<3) ; # I can set the maximum lenth of a suffix here
$prev = $_;
}
print "$_\n" for @reducedlist;

[Amazing to see how much time people can invest in a few lines of code
when they are no professionals ;-)! ]


#!/usr/bin/perl
use strict ;
use warnings ;

my @reducedlist ;
my $prev = quotemeta '......' ;

while ( <> )
{
s/\W+$// ; # chop-chop

next if / \A $prev .{0,3} \z /x ;

push @reducedlist, $_ ;
$prev = quotemeta ;
}
print "$_\n" for @reducedlist;

(untested)

--
Affijn, Ruud

"Gewoon is een tijger."


.



Relevant Pages

  • Re: Row Compression
    ... Otherwise, use Jim's suggestion ... > And want to remove rows with a blank in column 1 and collapse the whole ... > array to get: ... Prev by Date: ...
    (microsoft.public.excel.misc)
  • Re: Affordable Postscript Printers
    ... Thanks to one suggestion, ... at the Brother printer. ... Prev by Date: ...
    (comp.periphs.printers)
  • Re: just-dial saver
    ... They are having very bad reviews at the moment, not answering emails, no ... confirmation emails etc. ... The suggestion is that they're not bothered as they ... Prev by Date: ...
    (uk.telecom)
  • Re: Report writing in PHP - what tools for making formating nice?
    ... This way you can layout the whole thing the way you ... have been in word and the text document will import the exported file ... Just a suggestion. ... Prev by Date: ...
    (comp.lang.php)
  • Re: Is it possible to use an Object as value for a (im using struts)
    ... I could get the pair of values and concatenate the with some character, ... and them split them in the Action that follows the jsp to have them as ... Any suggestion? ... Prev by Date: ...
    (comp.lang.java.programmer)