Hi Rob, Rob Dixon wrote on 29.04.2004:
>Jan Eden wrote: >>The obvious problem is, that the variables are not interpolated >>according to their current value in the scripts, i.e. although >> >>$mother_id = 453; and $title = "Title"; >> >>The $page_head variable will an contain empty title tag and >>show_local.pl parameter after the do command. > >Hi Jan. > >I felt like a quick Perl 'fix' :) > Reminds me of our last do/eval discussion. I seem to never learn it. I never seem to learn it. ;-) While we're talking about scope. >perldoc -f do says: > >[do] also differs in that code evaluated with "do FILENAME" cannot >see lexicals in the enclosing scope; "eval STRING" does. > Ok, but $mother_id and $title are not lexicals within the html code. Or are they? Or, wait... the enclosing scope refers to the scope enclosing the expression evaluated? So it's the outer $mother_id and $title which cannot be seen. >so you need to eval the contents of a file. If in page_head.pl you >write this: > >q{ qq{ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC >"-//W3C//DTD XHTML 1.0 Transitional//EN" >"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html >xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"> <head> ><title> $title </title> </head> <body> <a >href="show_local.pl?id=$mother_id" class="head" target="_self">UP</a> ><div class="textbox"> <!-- begin content --> </body> </html> >}}; > >then I hope you can see that > >do 'page_head.pl' > >returns the string without the enclosing q{ .. }. i.e. the >double-quoted string that you want to eval. So you can then write > >use strict; use warnings; > >my $title = 'Title'; my $mother_id = '453'; > >print eval do 'page_head.pl'; > Dang. do AND eval. That's looks terribly smart to me, although someone less dim witted than myself would have seen this himself. Or herself, for that matter. Thanks a lot, Rob. You are one of the most helpful people around. - Jan -- A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>