Home 


 
 

Perl Array Variables


IN THIS ARTICLE

What is an Array Variable?

An array variable can be stated as a list of scalars, which can be a numbers and strings. An array variable can store many values. The difference between an array variable and a scalar variable is that array variable can store many values, while scalar variable can store a single value.

The first element of an array variable is referred as 0. Perl array variables start with a symbol "@".

perlarrayvariablescript1.pl

The complete Array Variable script

#!/usr/bin/perl
###############################################
# Author : Togotutor
# Description : Perl Array Variable Script
##############################################
print \"Content-type: text/html\\n\\n\";
@numbers = (1, 2, 3, 4); #Array variable numbers with assigned value as 1, 2, 3, 4
print \"@numbers[0]\\n\";
print \"@numbers[1]\\n\";
print \"@numbers[2]\\n\";
print \"@numbers[3]\\n\";
exit#script will exit now

Output

1
2
3
4
                        


perlarrayvariablescript2.pl

The complete Array Variable script

#!/usr/bin/perl
###############################################
# Author : Togotutor
# Description : Perl Array Variable Script
##############################################
#!/usr/bin/perl
print \"Content-type: text/html\\n\\n\";
#Array variable colors with assigned value as blue, green, yellow
@colors = (\"blue\", \"green\", \"yellow\");
print \"@colors[1]\\n\";
exit#script will exit now

Output

green

The above examples will give a basic idea on what is perl array variable and how to use it.



How to Link to This Page

It will appear on your page as:

Perl Array Variable




© 2010 ToGoTutor | Copyright | Privacy Policy | |Subscribe to togotutor.com newsfeed|