http://www.perlmonks.org?node_id=1227287


in reply to Re^3: Grep Pattern
in thread Grep Pattern

> that's elegant..

One should even be able to shorten it to (can't test right now)

 grep { (0,1,1,0)[ $_ % 4 ] } 0..12;

But it's not as DRY, cause you need to change the 4 if you change the list.

And of course it's not answering the OP s real question to filter any list.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^5: Grep Pattern
by ikegami (Patriarch) on Dec 15, 2018 at 15:48 UTC

    I was about to say it also creates a shitload of scalars, but it doesn't. `0,1,1,0` repeatedly places the same 4 scalars on the stack. They are created at compile-time and associated with the opcode that returns them. Not bad