Perl is a powerful script language which is much faster than simple shell script and there are lots of libraries that support virtually every tasks out there. But it is little difficult to learn at first.

One of the weak area of perl is that it doesn’t support multi dimensional array naturally. In order to implement multi dimensional array, you will need to use pointer references. (There may be other ways)

You can referece variable and array by adding "\" backslash in front of the variable.

For example

#create array
@a = (1,2,3,4,5,6);
 
#create reference to array a
$aref=\@a;

In order to access the variable,you just add the proper symbol in front of the var name.
You will need to use the referenced variable name with the ‘$’ sign intact.

  • if you are accessing it as a array , @$ref would refer to the whole array
  • if you are accessing the element of the array , $$ref[0] would refer the first element.
#To access the first element of the referenced array
print "first element: " . $$arref[1] . "\n";  # this will print '2'

Read the rest of this entry »