in reply to Split on every second character

When you use split, the pattern must match what separates what you want. In this case, the separator is the empty string between a character at an odd positions and a character at an even position. That's not exactly straightforward to match, but it's possible.

$ perl -E'say for split /(?!^|\z)(?(?{ pos()%2 })(?!))/, "0102030405"' 01 02 03 04 05 06

Here, it's simpler just to match what you want grab rather than what separates them, so just use a m//g:

$ perl -E'say for "0102030405" =~ /(..?)/sg' 01 02 03 04 05 06

Replies are listed 'Best First'.
Re^2: Split on every second character
by gri6507 (Deacon) on Feb 12, 2010 at 23:13 UTC
    No wonder getting the split() operator to work correctly was difficult. Thank you!