in reply to Using split() to divide a string by length
Another trick that works is to capture the split characters, which places them also in @fields and makes pos advance beyond them. Since all but probably the last group match, the normal split results mostly don't contain anything, so we need to filter out false elements with grep:
my $string = join '', a..z; my @fields = grep {$_} split /(.{3})/, $string; print "@fields\n"; __END__ abc def ghi jkl mno pqr stu vwx yz
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using split() to divide a string by length
by japhy (Canon) on Apr 13, 2006 at 19:51 UTC | |
by Zaxo (Archbishop) on Apr 13, 2006 at 20:58 UTC | |
by ikegami (Patriarch) on Apr 13, 2006 at 21:06 UTC |