How do I take a string in Perl and split it up into an array with entries two characters long each?
I attempted this:
@array = split(/../, $string);
If you really must use split, you can do a :
split
grep {length > 0} split(/(..)/, $string);
But I think the fastest way would be with unpack :
unpack
unpack("(A2)*", $string);
Both these methods have the "advantage" that if the string has an odd number of characters, it will output the last one on it's own.