in reply to Re^2: Is tie inteded to be used in this way? Few question arise
in thread Is tie inteded to be used in this way?

thanks but even if the code below runs well with all your improvements, as soon as i add a simply print "\@arr [@arr]\n"; at the end, the program hangs, eating a lot of memory. I dont understand why.
use strict; use warnings; sub trigger{print "Triggered: ",map {defined $_ ? " $_" : 'UNDEF'}@_," +\n"} { 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; shift()->$s(\@_) }; } } #package main.. tie my @arr, 'Arraytrigger'; print "\tSetting list:\n" and @arr = qw(a b c d e); #print "\tSetting one:\n" and $arr[0]=0; #print "\tpushing:\n" and push @arr,'f'; #print "\tpopping:\n" and pop @arr; #print "\tshifting:\n" and shift @arr; #print "\tunshifting:\n" and unshift @arr, 'zero'; #print "\tclearing with undef \@arr:\n" and undef @arr; #print "\tSetting list:\n" and @arr = qw(a); #print "\tSetting list:\n" and @arr = qw(a); #print "\tclearing with \@arr=():\n" and @arr=(); #my $ref = \$arr[0]; #print "\tsetting by reference:\n" and $$ref=11; #print "\tclearing:\n" and @arr=();#undef @arr and @arr=undef se +em no good..e # print "\@arr [@arr]\n"; #use Data::Dump;print dd(@arr);
thanks
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^4: tie example.. Code still hangs
by choroba (Cardinal) on May 01, 2015 at 19:02 UTC
    My mistake. The \ before @_ was there because of double quotes, so it should've been removed:
    *$_ = sub { &main::trigger; shift()->$s(@_) };
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ