Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl syntax in relation to references

Tags:

perl

Consider x is an array reference.

I know that [] gives an anonymous array reference and {} gives an anonymous hash reference. Now what does @{$x} mean?

like image 329
prashanthkvs Avatar asked Nov 30 '22 13:11

prashanthkvs


1 Answers

This means dereference an array ref.

You will see the content of the referenced array.

Note that you could use the simple

@$x

in your case.

The { } characters are needed when you have multiple levels in your data structure like in this example :

@{ $foo->{first_level}->{second_level} }

or

@{ $foo->[$first_level]->[$second_level] }

This works too with others sigils :

%{ } # HASH
$    # SCALAR

See perldoc perlreftut

like image 103
Gilles Quenot Avatar answered Dec 20 '22 04:12

Gilles Quenot