cees has asked for the wisdom of the Perl Monks concerning the following question:
I have often wondered how I can take the results of a function call that returns a scalar, and immediately pass a reference to that scalar to another function. It seems easy enough to do with Arrays and Hashes, but is it possible with Scalars?
sub get_string { return "the string" } sub put_string_ref { my $ref = shift; print "$ref -> $$ref\n"; } # Can I reduce the following two lines to one my $string = get_string(); &put_string_ref(\$string);
I have tried several things, like the following:
put_string_ref(\{get_string()}); put_string_ref(\${get_string()}); put_string_ref(\$&get_string); put_string_ref(\{&get_string});
but can't find anything that works. Am I missing the obvious, or is this just not possible?
In case anyone is wondering why I want to do this, I quite often take the output of HTML::Template and pass it to HTML::FillInForm as a scalar ref.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Working with references to scalars
by hv (Prior) on May 09, 2003 at 01:55 UTC | |
by cees (Curate) on May 09, 2003 at 02:55 UTC | |
by mvaline (Friar) on May 09, 2003 at 16:02 UTC | |
by cees (Curate) on May 09, 2003 at 19:35 UTC | |
|
Re: Working with references to scalars (even easier)
by tye (Sage) on May 09, 2003 at 03:25 UTC | |
|
Re: Working with references to scalars
by apsyrtes (Beadle) on May 09, 2003 at 02:05 UTC | |
|
Re: Working with references to scalars
by hmerrill (Friar) on May 09, 2003 at 13:26 UTC | |
by cees (Curate) on May 09, 2003 at 19:52 UTC |