Split Variable on white space

Just try using:

my @array1 = split(' ',$VAR1);

Codepad Demo

From Perldoc:

As another special case, split emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a literal string composed of a single space character (such as ' ' or "\x20" , but not e.g. / / ). In this case, any leading whitespace in EXPR is removed before splitting occur


If the first argument to split is the string ' ' (the space), it is special. It should match whitespace of any size:

my @array1 = split ' ', $VAR1;

(BTW, it is almost equivalent to your last option, but it also removes any leading whitespace.)

Tags:

Split

Perl