Finding the Length (Index Numbers) of an Array in Perl
To get the number of pieces in an array:
@ko=("London","Paris","France");
$ji=$#ko + 1;
print $ji;
Which Prints:
3
-We named our array
ko and stored 3 cities there.
-The pound symbol # after the $ but before the
ko says "what's the last index number of
ko?"
-The last index number is 2, remember index numbers start with 0.
-We added 1 to get 3.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
@ko=("London","Paris","France");
$ji=$#ko + 1;
print $ji;
exit;
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | CSS David McFarland |
| | | |
Dojo Matthew A. Russell... | | |