chuckd has asked for the wisdom of the Perl Monks concerning the following question:

I have a line of code like this:
$datfield{"text"} = gettext($text)
where $text is a string of text being passed into gettext().
the function gettext returns a reference to the text like return \$text.
how can I dereference the text value returned from gettext and place it into the hash value in one line. I don't want to have to split the lines.
  • Comment on dereferencing values returned from functions

Replies are listed 'Best First'.
Re: dereferencing values returned from functions
by FunkyMonk (Bishop) on Oct 24, 2008 at 22:41 UTC
    You can use ${ func() }:
    use Data::Dump 'pp'; # for display purposes only my %datfield; my $text = "some stuff"; $datfield{"text"} = ${ gettext($text) }; pp \%datfield; sub gettext { my $text = shift; return \$text; } __END__ { text => "some stuff" }

    Update: s/Date/Data/. Thanks oko1


    Unless I state otherwise, all my code runs with strict and warnings