Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Constant Variables

by The Mad Hatter (Priest)
on Mar 28, 2003 at 16:23 UTC ( [id://246500]=note: print w/replies, xml ) Need Help??


in reply to Re: Constant Variables
in thread Constant Variables

I think this might work (though I'm at school and I can't test it):
$dbh = CWT::Site_DB::connect(); $sth = $dbh->prepare (qq{ SELECT * FROM config_settings }); $sth->execute(); my %settings = %{$sth->fetchrow_hashref}; # I'm assuming you only + have one row... foreach my $key (keys %settings) { my $varname = "$" . $key; eval "$varname = $settings{$key}" or die "problem with eval"; } $sth->finish();
Also, from what you've said, it seems as if you are just using the settings to globally control the properties of HTML text so you only have to change the property in one place. If this is the case, then you should use CSS (Cascading Style Sheets) to define site-wide styles and include the CSS file in every page. CSS is a very powerful mechanism for easily changing the layout and design of a site.

Update: Hmm, I just saw that you want to use the values in the column name as the variable name. The code above uses the name of the field (or column) in MySQL as the variable name. Here is the code to do what you want:

$dbh = CWT::Site_DB::connect(); $sth = $dbh->prepare (qq{ SELECT * FROM config_settings }); $sth->execute(); while (my %settings = %{$sth->fetchrow_hashref};) { my $varname = "$" . $settings{name}; eval "$varname = '$settings{value}'" or die "problem with eval"; } $sth->finish();
That should do the trick, but it is also untested.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-28 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found