Splitting an ARRAY in Perl
Your information is in a variable you named $jiji
$jiji="London||Paris||Tokyo||";
You decide to name your ARRAY koko
@koko=split(/\|\|/, $jiji);
@koko now contains London Paris and Tokyo without the vertical bars.
You can access them with the following variables:
$koko[0] now equals London
$koko[1] now equals Paris
$koko[2] now equals Tokyo
print "$koko[0]";
Will print:
London
Another example:
The information you need is in a variable named $huhu
$huhu="London-Paris-Tokyo-";
You decide to name your ARRAY gy because it's easy to type
@gy=split(/-/, $huhu);
@gy now contains London Paris and Tokyo without the dashes.
You can access them with the following variables:
$gy[0] now equals London
$gy[1] now equals Paris
$gy[2] now equals Tokyo
print "$gy[1]";
Will print:
Paris
Copy and Paste Perl Script:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$huhu="London-Paris-Tokyo-";
@gy=split(/-/, $huhu);
print "$gy[1]";
exit;
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | |
CSS David McFarland | | |
| | | |