http://qs321.pair.com?node_id=1232767


in reply to Re^9: Getting for() to accept a tied array in one statement
in thread Getting for() to accept a tied array in one statement

The magic of tie seems to be strong. Even when using a reference to an element of a tied array one cannot bypass the associated class. And the access through the reference provides the correct index. So is this what happens when Perl aliases elements in a loop?

use strict; use warnings; package MyClass; use Tie::Array; our @ISA = ('Tie::Array'); our @data; # mandatory methods sub TIEARRAY { my $class = shift; bless \@data, $class; @data = @_ +; return \@data } sub FETCH { my ($self, $index ) = @_; print "FETCH($index)\n"; ret +urn $data[$index] } sub STORE { my ($self, $index, $value) = @_; print "STORE($index)\ +n"; $data[$index] = $value } sub FETCHSIZE { print "<FETCHSIZE> "; return scalar @data } package main; my @x; tie @x, "MyClass", 0, 0, 0; my $x = \$x[2]; $$x++; print "@x\n";