Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: In these times of economic crisis...

2 views
Skip to first unread message

Jasper

unread,
Apr 27, 2009, 5:35:56 AM4/27/09
to Phil Carmody, robert wilson, go...@perl.org
2009/4/26 Phil Carmody <thefa...@yahoo.co.uk>:
>
> --- On Sun, 4/26/09, robert wilson <hot...@safe-mail.net> wrote:
>> Phil Carmody wrote:
>> > We need dollar-free golf!
>> >
>> > In order to answer the question "what ratio of words
>> in the SOWPODS wordlist share no letters in common with the
>> word mackerel?", I quickly threw this together:
>> >
>> > perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
>> >
>> > However, there were complaints that it had too many dollar signs.
>> >
>> > What's the shortest equivalent script which uses no dollar signs at all?
>> >
>
>> perl -le 'print+(grep{/[mackrel]/}@w=<>)/@w' < sowpods
>
> Wow!!!
>
> It's obvious in retrospect. It's clear my original was horrifically wasteful, and can at least be shortened to this at the cost of one dollar:
> perl -le 'print+(grep{/[mackrel]/}<>)/$.' < sowpods

Shorter, with still one dollar. (actually, only shorter because you
have grep{} instead of grep with a comma, so the same)

perl -alp0e '$_=(grep/[mackrel]/,@F)/@F' < sowpods

Without the dollar, it's a bit longer, of course.

perl -aln0e 'print+(grep/[mackrel]/,@F)/@F' < sowpods

But that is the best I can do..
--
Jasper

(I'll send the tested one to the list, Phil)

Robert Wilson

unread,
Apr 26, 2009, 5:46:01 AM4/26/09
to Phil Carmody, go...@perl.org
Phil Carmody wrote:
> We need dollar-free golf!
>
> In order to answer the question "what ratio of words in the SOWPODS wordlist share no letters in common with the word mackerel?", I quickly threw this together:
>
> perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
>
> However, there were complaints that it had too many dollar signs.
>
> What's the shortest equivalent script which uses no dollar signs at all?
>
> Phil

perl -le 'print+(grep{/[mackrel]/}@w=<>)/@w' < sowpods
?

now, if you actually want the answer to the question "what ratio of
words in the SOWPODS wordlist share _no_ letters in common with the word
mackerel?", you'd need to add a "!", like this:
perl -le 'print+(grep{!/[mackrel]/}@w=<>)/@w' < sowpods

0 new messages