The Perl split function splits a string into an array. A string is splitted based on delimiter specified by pattern. By default, it whitespace is assumed as delimiter.
split syntax is:
Split /pattern/, variableName
In this example, split returns a list of strings. The delimiter is (-). It means string is splitted at (-).
my $str = "Cu-K-Na-Hg-Pb-Li"; my @break = split /-/, $str; print "@break\n";
We can limit the number of parts to be splitted for a string.
In this example, string splits in 3 parts.
my $str = "Cu-K-Na-Hg-Pb-Li"; my @break = split(/-/, $str, 3); print "@break\n";