Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL split Function



Syntax

split /PATTERN/, EXPR, LIMIT

split /PATTERN/, EXPR

split /PATTERN/

split


Definition and Usage

Splits a string expression into fields based on the delimiter specified by PATTERN. If no pattern is specified whitespace is the default. An optional limit restricts the number of elements returned. A negative limit has the same effect as no limit. This function is often used in conjunction with join() to create small text databases.

Return Value

  • Return Value in Scalar Context: Not recommended, but it returns the number of fields found and stored the fields in the @_ array.

  • Return Value in Array Context: A list of fields found in EXPR or $_ if no expression is specified.

Example

Try out following example:

#!/usr/bin/perl -w

@fields = split(/:/, "1:2:3:4:5");
print "Field values are: @fields\n";

It will produce following result:

Field values are: 1 2 3 4 5


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names