in reply to Re: Is tie inteded to be used in this way?
in thread Is tie inteded to be used in this way?

Thanks Eily, for suggestions, links and (never understood) to explain me the inutility of $self explicitally set, as i've done.
because $var->method(@params) already adds $var as the first parameter. was something i never realized.

Anyway is not clear to me what do you means with and I think you'll need to tie the contained scalars too if you want to call your trigger function only when your elements are modified. Your tied array should actually just tie any scalar pushed into it.
Are you refering in the case you change the value by reference (as i'll ask soon)? I have to tie the scalar values of each array elements?
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Is tie inteded to be used in this way?
by Eily (Monsignor) on Apr 29, 2015 at 08:00 UTC

    I thought that while cases like $array[42] = "Doky" would work fine, $array[42] =~ tr/y/i/ or even s/D/L/ for @array; would not call STORE, but I just tried and have been proven wrong, at least for v5.14 :

    sub trigger{print "Triggered ".shift."(@_)\n"} #must go BEFORE the eva +l is seen {#bare block because package BLOCK appeared only 5.14 package Arraytrigger; use Tie::Array; use vars qw(@ISA); @ISA = ('Tie::StdArray'); for (qw(STORE CLEAR PUSH POP SHIFT UNSHIFT)) { my $s = "SUPER::$_"; no strict 'refs'; *$_ = sub { main::trigger($s, @_); shift()->$s(@_) }; } } tie my @arr, 'Arraytrigger'; @arr = qw(Doky); $arr[0] =~ tr/y/i/; s/D/L/ for @arr;