in reply to Re: Elegantly Selecting Every 3rd Element in an Array.
in thread Elegantly Selecting Every 3rd Element in an Array.
my @every_3rd = @array[grep { ! (($_+1) % 3) } 0..$#array];
Update: Fixed (due to jerrygarciuh's catch). Nothing like untested code. And precedence. (though looking at the precedence table in perlop, it looks like what I had (in jerry's node below) should've worked. Bug? Can someone explain?).
Another update:tye explains below. Though I think precedence of parens should differ between 'functions' and 'operators'. Oh well...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Elegantly Selecting Every 3rd Element in an Array.
by jerrygarciuh (Curate) on Sep 29, 2001 at 02:37 UTC | |
by gbarr (Monk) on Sep 29, 2001 at 03:03 UTC | |
by runrig (Abbot) on Sep 29, 2001 at 03:15 UTC | |
by tye (Sage) on Sep 29, 2001 at 03:26 UTC |