tadman has asked for the wisdom of the Perl Monks concerning the following question:
Within the subroutine, I'm looking for a mechanism similar to wantarray which can return some information about what side of the assignment the sub is on. Here's what I'd like to be able to do:my $foo; my $foo_new; sub fooz : lvalue { $foo; } $foo = "Bar"; # Initialization print fooz,"\n"; # Reading fooz = "Foo"; # Assignment print fooz,"\n"; # Reading
Here the idea is that any writes go into $foo_new, while the reads come from $foo, unless of course there is a $foo_new, in which case they will read from $foo_new.my $foo; my $foo_new; sub fooz : lvalue { defined ($foo_new)? $foo_new : (islvalue? $foo_new = $foo : $foo); } $foo = "Bar"; # Initialization print fooz,"\n"; # Reading fooz = "Foo"; # Assignment print fooz,"\n"; # Reading
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Side Context in an 'lvalue' Subroutine
by broquaint (Abbot) on Mar 18, 2002 at 18:58 UTC | |
by tadman (Prior) on Mar 18, 2002 at 19:21 UTC | |
|
Re: Side Context in an 'lvalue' Subroutine
by Juerd (Abbot) on Mar 18, 2002 at 19:05 UTC | |
by tadman (Prior) on Mar 18, 2002 at 19:19 UTC |