broquaint has asked for the wisdom of the Perl Monks concerning the following question:
Now if I tie() my hash then the lvalueed method val() will die when called{ package foo; # not tied so all is well my %h = qw(one two three four); sub new { bless { val => \%h } } sub val : lvalue { $_[0]->{val}->{one} } } use Devel::Peek; my $obj = foo->new; $obj->val = "foo"; Dump( $obj->{val}->{one} ); __output__ SV = PV(0x80f9c40) at 0x80f9964 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x80f9018 "foo"\0 CUR = 3 LEN = 4
Firstly why does this happen, and secondly is there a way around it?{ package foo; use Tie::IxHash; tie(my %h, 'Tie::IxHash', qw(one two three four)); sub new { bless { val => \%h } } sub val : lvalue { $_[0]->{val}->{one} } } use Devel::Peek; my $obj = foo->new; Dump( $obj->{val}->{one} ); # dies here $obj->val = "foo"; __output__ SV = PVMG(0x8131170) at 0x8154b68 REFCNT = 1 FLAGS = (TEMP,GMG,SMG,RMG) IV = 0 NV = 0 PV = 0 ... many more lines of output Can't return a temporary from lvalue subroutine at - line 9
_________
broquaint
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: lvalue trickery
by Abigail-II (Bishop) on Jul 26, 2002 at 13:12 UTC | |
by broquaint (Abbot) on Jul 26, 2002 at 14:46 UTC | |
Re: lvalue trickery solution
by shotgunefx (Parson) on Jul 26, 2002 at 16:56 UTC | |
by broquaint (Abbot) on Jul 26, 2002 at 17:10 UTC | |
by shotgunefx (Parson) on Jul 26, 2002 at 17:18 UTC | |
Re: lvalue trickery
by RMGir (Prior) on Jul 26, 2002 at 12:53 UTC | |
by broquaint (Abbot) on Jul 26, 2002 at 12:59 UTC | |
by dada (Chaplain) on Jul 26, 2002 at 13:13 UTC | |
by RMGir (Prior) on Jul 26, 2002 at 13:09 UTC | |
Re: lvalue trickery
by Anonymous Monk on Jul 26, 2002 at 23:24 UTC |