Newsgroups: comp.lang.perl.misc
From: PerlFAQ Server <br...@stonehenge.com>
Date: Sat, 10 May 2008 18:03:02 -0700
Local: Sat, May 10 2008 9:03 pm
Subject: FAQ 4.22 How do I expand function calls in a string?
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.22: How do I expand function calls in a string? (contributed by brian d foy) This is documented in perlref, and although it's not the easiest thing print "The time values are @{ [localtime] }.\n"; If we want to call the function in scalar context, we have to do a bit print "The time is ${\(scalar localtime)}.\n" print "The time is ${ my $x = localtime; \$x }.\n"; If your function already returns a reference, you don't need to create sub timestamp { my $t = localtime; \$t } print "The time is ${ timestamp() }.\n"; The "Interpolation" module can also do a lot of magic for you. You can use Interpolation E => 'eval'; In most cases, it is probably easier to simply use string concatenation, print "The time is " . localtime() . ".\n"; -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They If you'd like to help maintain the perlfaq, see the details in You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||