in reply to Returning and using a glob from a sub.
Thank you one and all for your concise responses. I am sorry if I was a bit unclear and less than speedy in responding to the posts. I should have made my intentions clear; I don't have much experience with asking questions in a public forum like this one.
Essentially, I am creating a simple class, consisting of a constructor and an a method. The argument to the constructors sets the value of the datum, while the sub grants access to the datum.
I wanted to get around using explicit accessor and mutator methods and simply have a subroutine which, with a little syntactic sugar, could be used as a variable. I know, it sounds insane. Ne'ertheless, I shan't delve into my madness here.
My thinking, as unclear as it may seem, led me to believe a glob value could serve this dual purpose if one derefernced it properly:
package datum; our $value = undef; sub new { my $class = shift; local $value = shift; return bless { datum => $value, glob => *value }, $class } sub value { my $self = shift; return $self{glob} } 1
This "wants" to have the effect of returning an alias for the datum when used in a manner similar to the following:
use datum; my $d = datum->new(42); *d = $d->value(); # What I want to be able to here is something like: # $d = ...; $d->{foo} = ...; push @d, ...
Perhaps, this makes things a little more clear. Thank you in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Returning and using a glob from a sub.
by BrowserUk (Patriarch) on Dec 26, 2014 at 23:04 UTC | |
|
Re^2: Returning and using a glob from a sub.
by LanX (Saint) on Dec 27, 2014 at 00:23 UTC | |
|
Re^2: Returning and using a glob from a sub.
by LanX (Saint) on Dec 27, 2014 at 00:38 UTC |