© William "Bo" Rothwell of One Course Source, Inc. 2019
William "Bo" RothwellBeginning Perl Programminghttps://doi.org/10.1007/978-1-4842-5055-6_10

10. Perl Utilities

William “Bo” Rothwell1 
(1)
San Diego, CA, USA
 

split

The split statement is useful for breaking up a scalar value based on a particular character (or characters). It will return what is split as a list (array) of scalar values. This list is normally assigned to an array:
  DB<1> $str = "Bob:Jones:23423:manager:O3"
  DB<2> @fields=split(/:/, $str)
  DB<3> for $item (@fields) {print $i++, " $item\n";}
0 Bob
1 Jones
2 23423
3 manager
4 O3

Note

/:/ is actually a regular expression pattern.

Using $_

If the variable you are splitting is $_, you don’t need to specify the variable name; split will assume ...

Get Beginning Perl Programming: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.