#!/usr/bin/perl use strict; my @arr; #notice how arrays use @ before the name of the variable my $foo=0; #where "scalars" (ints, floats, strings, etc) use $ #arrays can be used just as in c/c++ while($foo<5) { @arr[$foo] = $foo * 5; $foo++; } print @arr[3]; print "\n"; #however perl adds many quick,usefull,and easy options and funtions for arrays. #first, you get the size of an array by assigning it to a scalar variable. my $size = @arr; print "$size \n"; #push and pop are available. $foo = pop @arr; push(@arr,4); #there is also shift, and unshift...which work with the first element instread of the last. $foo = shift @arr; unshift(@arr,67); #you can print an array if you want all the elements in a row. print @arr; #you can reverse an array my @rev = reverse @arr; print @rev; #and my favorite foreach, which will step throught each element in the array foreach $foo (@arr) { print "I have $foo chickens \n"; } #whats happening here is that the first trip through $foo is equal to @arr[0], the next time around #$foo is equal to @arr[1] and so on. #another neat little trick is negative array indexs. $foo = @arr[-1]; #this will assign the last element in the array to $foo. print $foo;