Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does \@array mean in Perl?

I have some Perl code where I noticed an array is used with a leading backslash like \@array

Can anybody explain what does it mean?

like image 446
shift66 Avatar asked Oct 25 '11 07:10

shift66


People also ask

How do I read an array in Perl?

To access a single element of a Perl array, use ($) sign before variable name. You can assume that $ sign represents singular value and @ sign represents plural values. Variable name will be followed by square brackets with index number inside it. Indexing will start with 0 from left side and with -1 from right side.

How do I dereference an array in Perl?

Dereferencing an array If you have a reference to an array and if you would like to access the content of the array you need to dereference the array reference. It is done by placing the @ symbol (the sigil representing arrays) in-front of the reference.

How do I count the size of an array in Perl?

Note: In Perl arrays, the size of an array is always equal to (maximum_index + 1) i.e. And you can find the maximum index of array by using $#array. So @array and scalar @array is always used to find the size of an array.

Do Perl arrays start at 0 or 1?

Access arrays with numeric valuesAll arrays in Perl start at 0. Arrays can also be accessed from the end by using negative offsets from the end. Reading a non-existent element gives undef .


2 Answers

the \@ notation will return a reference (or pointer) to the array provided, so:

$arrayref = \@array

will make $arrayref a reference to @array - this is similar to using the *p pointer notation in C.

like image 132
planetguru Avatar answered Nov 16 '22 02:11

planetguru


It means it's a reference to an array.

See the perl documentation that explains it well

like image 32
ccheneson Avatar answered Nov 16 '22 02:11

ccheneson