Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling function from with quotes

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
Can someone tell me how I would call a function from within quotes? Is this possible?

I have the function:

sub special_function(){
print "special stuff";
}

And would like to call it by from within quotes like this:

print "normal stuff ${main::special_function()} more normal stuff";


I know this seems strange, but I really have a very good reason for wanting to do this. Is it possible? What I have written doesn't work, but hopefully you get the idea of what I want to do.
 
I think I got it, as this seems to work:

print "normal stuff ${\&special_function()} more normal stuff";
 
Actually, it is not quite working correctly.

The output for the function call is getting sent out before the prior string contents.

I am getting this:
special stuff normal stuff more normal stuff

instead of this:
normal stuff special stuff more normal stuff

I tried adding chaning the output buffer, but this doe not seem to help:
$|=1;

Any suggestions?
 
You will want to change the function so that it returns the string instead of printing it. Otherwise you will print the return value of the function, too. (The '1' that you are probably seeing)
Code:
sub special_function(){
 return "special stuff";
}

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top