Create Free Websites
Create a Free Website at Ucoz
GrrooP.com
Jimdo.comSign Up
MoonFruit


Create Your Own
Designs

Without Tables

Artisteer - Web Design Generator

Use your knowledge of HTML to turn your template into a website.

Download a FREE Trial

PERL CGI Tutorial
for Writing Interactive Form Scripts

Using the Split Function of PERL

In the previous lesson we opened a file that we had saved and displayed its contents in the web browser. The file was displayed exactly as it was saved with 2 strings connected using a pipe symbol. In this lesson we'll remove the pipe symbol and restore the strings to their original values using PERL's split function.

The code for the split function is shown below. On the left side of the equal sign we list the original values in the order they were saved. We place the character that was used to separate them between the 2 forward slashes. In this case it will be the pipe symbol, which must be preceded by a back slash. ( \| )

Note: Some symbols which have a reserved meaning or purpose in PERL must be escaped or preceded by a back slash. The pipe symbol is one of them.

The string that we will perform the splitting action on is placed after the forward slashes. (note comma)

($string1,$string2) = split(/ /,$line);

The line that we used to save the file in parse_form.pl was
print INFO "$last|$first\n";
The code that we will use to split the line is:
($last,$first) = split(/\|/,$line);


foreach $line (@array){
($last,$first) = split(/\|/,$line);
print "First name: $first Last name: $last<br>\n";
}

Open display_file.pl and make changes as shown in the code above. The lines that we are adding or modifying are in red. After you make the changes save display_file.pl and run it on the server. You will need to press the Refresh button to see the change.