[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] How to interpolate a function call in a string



I know that interpolating function calls in strings raises some time 
issues, like, which pass of the compiler should make the call? But I 
would really like the convenience of calling a character code set 
translation function from text passed to qq(). So I tried testing it with 
the following:


# Examples for interpolating function calls in string literals:

sub thing()
{	return "mono";
}

print "Since I can do this: ", thing(), "\n\n";

print "I don't really need this in a string: thing()\n";

print qq(
but, 
I would really like to be able to do this in a qq:
thing()
);

print qq(
I tried this in both qq:
&thing()
);
print "and strings: &thing()\n\n";

my $callThing = thing;
print qq(
And I guess I can do this in qq: 
$callThing
);
print "and in strings: $callThing\n\n";

print "But I want parameters:\n";
sub thing2( $ )
{	return "duo$_[ 0 ]";
}
# Can't do this at all:
# my $callThing2 = thing2;
my $callThing2 = thing2( "Will this help me?" );
print qq(
What happens when I want to use a different parameter?
$callThing2( "Fat chance!" );
);
# 
print "nor in string: $callThing2( \"Fat chance!\" )\n\n";

my $refThing2 = \&thing2;
print "A reference doesn't help: $refThing2(\"mustard gas\")\n";
# print "Error (undefined sub): ${refThing2(\"mustard gas\")}\n";
# print "Error (undefined sub): ${&refThing2(\"mustard gas\")}\n";

# (The backslash character (\) is going to look like the 
# symbol for yen most of the time in Japan, BTW.
# I wonder what it looks like in some parts of Europe?)



rees_joel@fujicomp.co.jp
http://www.fujicomp.co.jp
http://www.udit.gr.jp


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org