in reply to split every other value

In the spirit of TMTOWTDI...
$list = '1,2,3,4,5,6,7,8'; @odds = grep $_ % 2, split(/,/, $list); @evens = grep not($_ % 2), split(/,/, $list);
Update: just read the part about text not numbers, so this might be more appropriate...
$list = 'a,b,c,d,e,f,g,h'; $i=0; @pos1 = grep not($i++ % 2), split(/,/, $list); $i=0; @pos2 = grep $i++ % 2, split(/,/, $list);


-- All code is 100% tested and functional unless otherwise noted.

Replies are listed 'Best First'.
Re^2: split every other value
by Aristotle (Chancellor) on Aug 07, 2004 at 00:26 UTC

    That requires iterating over the list twice, though.

    Makeshifts last the longest.