in reply to Re: Array Parse
in thread Array Parse

I would not actually recommend this (except for an obfuscation maybe) but I thought it deserved mention anyway:

my @even = grep --$|, @array;

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: Array Parse
by Gilimanjaro (Hermit) on Jan 20, 2003 at 14:48 UTC
    Obfuscation indeed! What makes this tick? I though the $| had to do with pipes, plumbing and toilets! Please explain?
      Perhaps this helps:
      #perl -e 'print --$| foreach (1..10)' 1010101010

      rdfield

      $! is tied to a variable that is a bit. Therefore it can only be 0 and 1. Set it to a true value and it sets itself to 1. Set it to a false one and it becomes 0. So subtracting 1 from it when it is 0 gives -1 (true) and sets it to 1. Subtracting 1 from 1 gives 0 again.

      When you know how it works, not that complex. But when you first see it it is a bit surprising... (Cue groans.)