A little text file munging golf on the list

[email protected] (Andrew Savige)
Newsgroups perl.golf
Message-ID <[email protected]>
The problem is to transform, say:

f.$d billy
f.$d knob
f.$d hagus
knob fred
hermione harry
f.$d john
yanick keith
yanick eugene

into:

f.$d billy knob hagus
knob fred
hermione harry
f.$d john
yanick keith eugene

The input text file contains no blank lines.
Every line consists of two fields separated by a single space.
The last line is properly newline-terminated.
Don't worry about an empty input file.

Some nameless amateur golfers have come up with the following
solutions, all with the same golf score:

#!perl -p
s/\S+/$&ne$l&&$m.($l=$&)/e;$m=eof||chop

#!perl -0ap
$:="\n$F[0]";s/\n\S+/$:=$&if$&ne$:/eg

#!perl -0p
/ /;$:="\n$`";s/\n\S+/$:=$&if$&ne$:/eg

Improvements welcome.

/-\


http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.