This section provides a tutorial example on how to use symbolic references with the dereference operator like EXPR->[*], EXPR->{*}, or EXPR->(*) for array elements, hash elements and function calls.
As mentioned in the previous section,
if a symbolic reference is used with a subscription of [*], {*}, or (*), the dereference operator,
-> can be used between the identifier string expression and the subscription.
Note that subscription [*] is used for array elements, {*} is used for hash elements, (*) is used for function calls.
The following tutorial program shows you some examples. Note that you can not use -> to
access hard slices.
#- SoftRef3.pl
#- Copyright (c) 1999 by Dr. Herong Yang, http://www.herongyang.com/
#
$name = 'foo';
@name = ('foo');
%name = ('i', 'foo');
$name->[0] = 30; print "$foo[0]\n";
$name->[0,1] = (40,41); print "$foo[0]\n"; # not working
$name->{'k'} = 60; print "$foo{k}\n";
$name->{'k','l'} = (70,71); print "$foo{k}\n"; # not working
$name->(80);
'foo'->[0] = 130; print "$foo[0]\n";
('bla','foo')->{'k'} = 160; print "$foo{k}\n";
('f'.'oo')->(180);
$name[0]->[0] = 230; print "$foo[0]\n";
$name{'i'}->{'k'} = 260; print "$foo{k}\n";
&name->(280);
sub foo {print "$_[0]\n";}
sub name {return 'foo';}