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.
In reply to Working with references to scalars by cees
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |