Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Small golfing trick
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Philippe 'BooK' Bruhat  
View profile  
 More options Mar 23 2006, 5:40 pm
Newsgroups: perl.golf
From: philippe.bru...@free.fr (Philippe 'BooK' Bruhat)
Date: Thu, 23 Mar 2006 23:40:23 +0100
Local: Thurs, Mar 23 2006 5:40 pm
Subject: Small golfing trick
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))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jasper  
View profile  
 More options Mar 24 2006, 4:14 am
Newsgroups: perl.golf
From: jaspermcc...@gmail.com (Jasper)
Date: Fri, 24 Mar 2006 09:14:18 +0000
Local: Fri, Mar 24 2006 4:14 am
Subject: Re: Small golfing trick
On 3/23/06, Philippe 'BooK' Bruhat <philippe.bru...@free.fr> wrote:

>     perl -ne'$s{$_}++||print' file

> with

>     perl -ne'$$_++||print' file

> Three characters in one shot!

I think MTV used this in the palindrome golf, at least. So it's been
around for a while :)

Jasper


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Philippe 'BooK' Bruhat  
View profile  
 More options Mar 24 2006, 5:24 am
Newsgroups: perl.golf
From: philippe.bru...@free.fr (Philippe 'BooK' Bruhat)
Date: Fri, 24 Mar 2006 11:24:33 +0100
Local: Fri, Mar 24 2006 5:24 am
Subject: Re: Small golfing trick
Le vendredi 24 mars 2006 à 09:14, Jasper écrivait:

> On 3/23/06, Philippe 'BooK' Bruhat <philippe.bru...@free.fr> wrote:

> >     perl -ne'$s{$_}++||print' file

> > with

> >     perl -ne'$$_++||print' file

> > Three characters in one shot!

> I think MTV used this in the palindrome golf, at least. So it's been
> around for a while :)

I was pretty sure this wasn't original, but I liked the feeling when I
thought "by the way, the symbol table is just a hash!".

With the help of :: (or rather '), one can even build up nested data
structures, I think...

--
 Philippe "BooK" Bruhat

 Your reputation is what you make of it... and what you choose to take with
 you.                               (Moral from Groo The Wanderer #48 (Epic))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
j...@natura.di.uminho.pt  
View profile  
 More options Mar 31 2006, 5:15 am
Newsgroups: perl.golf
From: j...@natura.di.uminho.pt
Date: Fri, 31 Mar 2006 11:15:08 +0100
Local: Fri, Mar 31 2006 5:15 am
Subject: Re: [Cog-book] Small golfing trick
* Philippe 'BooK' Bruhat (philippe.bru...@free.fr) wrote:

> 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

Whoo, nice :-) I'll add it to my notes, thanks :-)

> 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))
> _______________________________________________
> Cog-book mailing list
> Cog-b...@perl-hackers.net
> http://perl-hackers.net/mailman/listinfo/cog-book

--
Jose Alves de Castro <c...@cpan.org>
      http://jose-castro.org/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eirik Berg Hanssen  
View profile  
 More options Mar 31 2006, 9:09 am
Newsgroups: perl.golf
From: Eirik-Berg.Hans...@allverden.no (Eirik Berg Hanssen)
Date: Fri, 31 Mar 2006 16:09:12 +0200
Local: Fri, Mar 31 2006 9:09 am
Subject: Re: Small golfing trick
philippe.bru...@free.fr (Philippe 'BooK' Bruhat) writes:

> Compare the classic "remove duplicate lines" one-liner

>     perl -ne'$s{$_}++||print' file

> with

>     perl -ne'$$_++||print' file

> Three characters in one shot!

  It has its limitations though.  Like namespaces:

~$ perl -e 'print"a\n::a\nmain::a\n::main::a\n"; ' | perl -ne'$$_++||print'
a
~$

  ... and missing newlines:

~$ perl -e 'print"a\n1"; ' | perl -ne'$$_++||print'
a
Modification of a read-only value attempted at -e line 1, <> line 2.
~$

Eirik
--
For every complex problem, there is a solution that is simple, neat, and wrong.
                -- H. L. Mencken
A good plan today is better than a perfect plan tomorrow.
                -- Patton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ton Hospel  
View profile  
 More options Apr 2 2006, 6:20 am
Newsgroups: perl.golf
From: perl-g...@ton.iguana.be (Ton Hospel)
Date: Sun, 2 Apr 2006 10:20:33 +0000 (UTC)
Local: Sun, Apr 2 2006 6:20 am
Subject: Re: Small golfing trick
In article <7xwteawvsn....@blackbox.eirik.dav>,
        Eirik Berg Hanssen <Eirik-Berg.Hans...@allverden.no> writes:

In real golfing the limitation that bites you most is the direct version
of what causes the problem above: $$_ doesn't work as storage space if
$_ is a postive integer. Though this can sometimes be worked around by
using @$_ or $#$_

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »