in reply to Re: removing repeats
in thread removing repeats

Hi again,
Thanks for your very prompt reply but it is the words that are adjacently repeated that I want to print. I can do this part, but what my script does is print out all these repeats instead of just showing the repeat once, so for example if a line contains the word hello eight times in a row, i only want this word to show once. here's my script.
I will be very grateful for your help. Thank you!!

#!/usr/bin/perl # rcwords.pl: print immediately adjacent repeated words once from inpu +t, # even if they are repeated more than once, # and print out these words along with the line number(s) that they ap +peared. use English; use diagnostics; $prevword = ''; $n = 0; while ($line = <>) { $n = $n + 1; $line =~ s/[[:punct:]]/ /g; $line = lc $line; @words = split /[[:space:]]+/, $line; foreach $word (@words) { if ($word ne '') { if ($word eq $prevword) { unless ($prevword eq $prevword) { print " $n $word\n"; } } $prevword = $word; } } }

Edit by BazB. Add code tags.