your question has already been answered, you have to pass references.

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.

sub new { my $class = shift; local $value = shift; return bless { datum => $value, glob => *value }, $class }
the only "slot" holding the value is $obj->{datum}

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.