CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Evaluating variables

 



AlanB
Novice

Jun 9, 2003, 6:02 AM

Post #1 of 2 (497 views)
Evaluating variables Can't Post

Hi

This is a problem which I used to be able to handle quite well in the BASIC language but not sure if it can be done in Perl.

I have a template file stored which contains info on the output display. In this file I have things like:

$b - which is set up in main script to equal <strong>
$c - set up to equal <center>

and so on.

The script reads through the template file and takes each value into a variable $tpl. Now what I am trying to do is print out the value of the Variable read into $tpl!!!

At the moment all I get is an output of $b or $c when what I really want is to evaluate the content of $tpl and print out <strong><center> etc. Does this make sense?

I believe BASIC offers an EVAL statement so that

print EVAL($tpl) will print the value of $b ($c)... and not the value of $tpl.

Can anyone advise how I can achieve this?

Thanks

Alan


Paul
Enthusiast

Jun 9, 2003, 8:45 AM

Post #2 of 2 (494 views)
Re: [AlanB] Evaluating variables [In reply to] Can't Post

In your file you could do:


Code
{ 
a => '<strong>',
b => '<center>'
}


Then load the contents using:


Code
    my $data = do($path_to_file) or die "Can't do $path_to_file: $!";


Then grab what you want with something like:


Code
    my $center = $data->{b};



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives