Category: >> Perl Code >> Get every 2nd (or 3rd, 4th, ...) element of an array Bookmark and Share

<< lastnext >>

Snippet Name: Get every 2nd (or 3rd, 4th, ...) element of an array

Description: This snippet gets the 'xth' elements of an array. In this case, the '% 2' selects every other element. Using '% 3' would get every 3rd element.

Also see:
» Select text in a DIV, SPAN, or tab...
» Randomize an array
» Removing duplicate array items whi...
» Grab the last element of an array
» Create an array from the contents ...
» Create an array from comma separat...
» Get the computed style of an eleme...
» Find All Elements By Class
» Dynamically create HTML elements
» Dynamically add and remove elements
» Search array elements for a substr...
» Get and set select lists with Java...
» Selecting a Random Row
» Unset unkown array element
» FLASHBACK: Syntax Elements
» TABLE - Using Select Statement Wi...
» SELECT: Case insensitive search
» SELECT: Partition Select
» SELECT: Select For Update
» SELECT: Using Functions
» SELECT: Scalar Select
» SELECT with HAVING Clause
» SELECT with GROUP BY Clause
» SELECT with WHERE Clause
» SELECT with SAMPLE clause
» SELECT placement
» SELECT into a table

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: December 03rd, 2010

@arr1 = ("zero", "one", "two", "three", "four");
@arr2 = grep{!($n++ % 2)} @arr1;
print "@arr2";
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 8