Home » Perl split() Function

Perl split() Function

by Online Tutorials Library

Perl split Function

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:


Perl split Example

In this example, split returns a list of strings. The delimiter is (-). It means string is splitted at (-).

Output:

  Cu K Na Hg Pb Li  

Perl split Limit number of parts

We can limit the number of parts to be splitted for a string.

In this example, string splits in 3 parts.

Output:

Cu K Na-Hg-Pb-Li

You may also like