How to Convert Array References in Perl
Perl, a practical extraction and report language, is a high-level programming language you use in Web applications and data processing. As other languages of this type, Perl offers you the feature to dynamically allocate memory at run-time and refer to it via references, similar to C pointers. A reference contains a description of data type and a pointer to a location in memory. You can use Perl references to refer to an array variable, and dereference to return the data in the array.
Instructions
-
-
1
Type the following code to create a reference to a constant array:
$array_reference = [1, 5, 10, 100];
If you print "$array_reference" you will see something along the lines of:
ARRAY(0x80f6c6c)
-
2
Type the following code to create a reference to an existing array:
$array_reference = \@some_Array;
-
-
3
Place the '@' operator before the reference variable to dereference the array reference:
@my_array_data = @$array_reference;
If you were to print this, using the data in Step 1, you would see:
1 5 10 100
-
4
Type the "->" arrow operator as below to dereference an element of the referenced array:
$first_array_element = $array_reference->[0];
This would return the value "1" using the example array from above.
-
1