develooper Front page | perl.golf | Postings from March 2006

Small golfing trick

Thread Next
From:
philippe.bruhat
Date:
March 23, 2006 14:40
Subject:
Small golfing trick
Message ID:
20060323224023.GA20940@localhost.localdomain
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))

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About