Sorta. You can use @{[ ... ]} to interpolate code within quotes, like so:
print <<"BLAH";
This is the start of it...
@{[ evaluated_code($blah) ]}
This is the end of it.
BLAH
sub evaluated_code {
if ($blah == $blah) { return $blah }
}
Don't use 'print' in your inner code, or the results will not be what you expect.
stephen
| [reply] [d/l] [select] |
Yes, it is. Do something like this:
$var=<<BLAH;
if($lbha = 'poo'){
print "oh";
}
BLAH
eval $var;
You're probably wondering about that little eval $var part. Well, all eval does is evaluate the code and execute it as a separate script. Otherwise you would just literally print "if($lbha = 'poo'){
do stuff....
}" out of the screen, which isn't what you want.
I hope I understood your question and answered it properly.
Tiptoeing up to a Perl hacker. Dave AKA damian
| [reply] [d/l] [select] |
Lets say that inside a
$var=<<VAR;
print "Blah";
VAR
print<<BLAH;
print "Blah";
eval $var;
BLAH
will that replace eval $var with "Blah"?
| [reply] [d/l] |
print "Blah";
eval print "Blah";
;
as your output, which is probably not what you want.
See Masem's post and stephen's post below for how to do more interesting interpolation.
If God had meant us to fly, he would *never* have give us the railroads.
--Michael Flanders | [reply] [d/l] [select] |
$var=<<BLAH;
print "Blah";
BLAH
eval $var;
Because when it executes it it will print Blah out on the screen because you have print "Blah"; already inside $var;
UPDATE:WOULD SOMEONE MIND TELLING ME WHAT IS SO WRONG ABOUT THIS POST THAT I GOT A -- ON IT?? THIS IS SO *beeping* REDICULOUS. CONSTANTLY BEING ATTACKED.
Tiptoeing up to a Perl hacker. Dave AKA damian
| [reply] [d/l] [select] |
It sounds like you can do one of two things:
Use a subroutine that you can pass values to and that prints everything out. You don't have to worry about storing all that text into a single variable, and you have a lot more flexibility with this method. If you go this route, you should pass any arguements you have as a signle hash so that you don't have to worry about messing up the order of the arguements.
Alternative, you could use a template module, like Template Toolkit 2 or HTML::Template, which have some basic logic structures that you can actually embed within the text to do what appear to need it to do.
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
| [reply] |