- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl split Function
Description
This function 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.
Syntax
Following is the simple syntax for this function −
split /PATTERN/, EXPR, LIMIT split /PATTERN/, EXPR split /PATTERN/ split
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
Following is the example code showing its basic usage −
#!/usr/bin/perl -w @fields = split(/:/, "1:2:3:4:5"); print "Field values are: @fields\n";
When above code is executed, it produces the following result −
Field values are: 1 2 3 4 5
perl_function_references.htm
Advertisements
To Continue Learning Please Login
Login with Google