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";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^11: Getting for() to accept a tied array in one statement [TANGENT: untie attempted while # references still exist]
by pryrt (Abbot) on Apr 18, 2019 at 17:09 UTC | |
by hdb (Monsignor) on Apr 18, 2019 at 18:03 UTC | |
Re^11: Getting for() to accept a tied array in one statement
by LanX (Saint) on Apr 19, 2019 at 12:37 UTC |
In Section
Seekers of Perl Wisdom