Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 





Split Function in an array


Tutorials Perl

Topic

What is split Function?
How to delimit a string using perl?



Explanation
Split function:

Split() is used to split or delimit a string to make an array, by using the specified delimiters.

Syntax:
     split( delimiter, string); 

In the above syntax "delimiter" is the delimit operator or symbol to be used, "string" specifies the string to split.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $fruits="grapes+cherry+orange";
    @f=split(/\+/,$fruits); 
    print "@f"; 
Result:
    grapes cherry orange

In the above example, the split function delimit the + symbol and displays an array element. The string has "+" as the delimiter, to know that its not an operator but a delimiter we use the backslash in between forward slashes. Now the string is split into an 3 element array.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $fruits="grapes:cherry:orange";
    @f=split(/:/,$fruits); 
    print "@f"; 
Result:
    grapes cherry orange

In the above example, we used ":" as the seperator to split string, here we use only two forward slashes, not the backward slash in between as ":" is not an operator like "+" symbol.








A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting