The split function splits up a string EXPR by some delimiter (whitespace by default) and returns an array.
#If a string is not supplied as the expression, the $_ string is split.
#You can specify more than one delimiter, using the regular expression metacharacter [ ].
#[ +\t:] represents zero or more spaces or a tab or a colon.
#LIMIT specifies the number of fields that can be split.
#Format:
#split("DELIMITER",EXPR,LIMIT)
#split(/DELIMITER/,EXPR,LIMIT)
#split(/DELIMITER/,EXPR)
#split("DELIMITER",EXPR)
#split(/DELIMITER/)
#split
# Splitting a scalar on whitespace and creating a list
$line="a b c d e";
@letter=split(' ',$line);
print "The first letter is $letter[0]\n";
print "The second letter is $letter[1]\n";
Related examples in the same category