Tuesday, October 14, 2008

Arrays and foreach loop

#!/usr/bin/perl -w

#Define array
@myArray=(1,2,3,4,5,6,7);

#foreach loop
foreach $myVal(@myArray)
{
print($myVal);
print("\n");
}

#To reverse the array
print("Reverse Array \n");
foreach $revVal(reverse @myArray)
{
print($revVal);
print("\n");
}

#Directly print Array

print("@myArray \n");

No comments: