But the code you are showing has too many issues.
this doesn't make sense since $value is localized and will be deleted after new() returns.
the only "slot" holding the value is $obj->{datum}sub new { my $class = shift; local $value = shift; return bless { datum => $value, glob => *value }, $class }
then be aware that $self is supposed to hold an object (i.e. blessed hashref), you have to deref $self properly
sub value { my $self = shift; # return $self{glob} # will never work return $self->{glob} # might work }
finally this is nonsense, you can't use a glob sigil with a private variable my $d
my $d = datum->new(42); *d = $d->value();
your alias must be a package var.
If you really want to go on with shortcuts, why not simply try a scalar ref?
my $datum = \ $obj->{datum}; # and then $$datum = ...;
> # $d->{foo} = ...; push @d, ...
well hashes and arrays must be refs anyway...
so you'll need to write things like
$datum->{foo}=...; push @$datum,...;
But plz be aware that you are now committing crimes against many laws of OOP!
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
In reply to Re^2: Returning and using a glob from a sub.
by LanX
in thread Returning and using a glob from a sub.
by mephtu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |