I thought I might be able to pass a negative number to FETCH if the index was negative and bigger than the number of elements.
Turns out FETCH is not even called in that situation, even though FETCH *is* called for indexes greater than the highest existing index.
use Tie::Array qw( ); our @ISA = 'Tie::StdArray'; sub FETCH { my ($self, $idx) = @_; warn("Fetching index $idx\n"); return $self->SUPER::FETCH($idx); } my @a; tie @a, __PACKAGE__; $#a = 4; my $s; $s = $a[-@a+1]; # Fetching index 1 $s = $a[-@a]; # Fetching index 0 $s = $a[-@a-1]; # FETCH not called! $s = $a[@a]; # Fetching index 5
Perl 5.6.1 & 5.8.6
In reply to Re^2: Interesting SEEK behavior on tied filehandle ($x[-@x-1])
by ikegami
in thread Interesting SEEK behavior on tied filehandle
by GammaRay Rob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |