in reply to Removing repeated words

Update: How 'bout a 1 liner?
perl -pale '$_="@{[grep !$s{$_}++, @F]}"'
original attempt below...

my %seen; print join(' ', grep !$seen{$_}++, split), "\n" while <STDIN>;

-Blake

Replies are listed 'Best First'.
Re^2: Removing repeated words
by Aristotle (Chancellor) on Sep 20, 2002 at 15:08 UTC
    ++, this is more a -n than -p task though. perl -lane 'print grep !$s{$_}++, @F'

    Looks quite a bit less daunting, not don't it. :-)

    Update: good catch, blakem++. The devil is in the details, they say in German..

    Makeshifts last the longest.

      The words run together if you just print the list, though $, can take care of that....
      % perl -lane 'print grep !$s{$_}++, @F' one two two three onetwothree % perl -lane '$,=$"; print grep !$s{$_}++, @F' one two two three one two theee

      -Blake