Small golfing trick
[email protected] ((Philippe 'BooK' Bruhat)) Thu, 23 Mar 2006 23:40:23 +0100
| Newsgroups | perl.golf |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I just discovered this, and do not know if it's commonly used in golf
(it's been a long time since I last played): if you only need a single
hash in your script, you can use the symbol table itself.
Compare the classic "remove duplicate lines" one-liner
perl -ne'$s{$_}++||print' file
with
perl -ne'$$_++||print' file
Three characters in one shot!
--
Philippe "BooK" Bruhat
The learned man makes a mistake but once... but the truly stupid keep
practicing until they get it right.
(Moral from Groo The Wanderer #75 (Epic))