in reply to Dynamic Settings from Database, $$string help

Thanks for both you input, I appriciate the help.

Neither of the solutions seem just right however.

my %settings; while ((undef, my ($name, $value)) = $sql->fetchrow_array()) { $settings{$name} = $value; }

I did:
my %settings; while ((my ($tmp,$name, $value)) = $sql->fetchrow_array()) { $settings{$name}=$value; } $sql->finish(); print $lastlog."\n";

Which returned nothing. lastlog is a 'name' and should be = 300000
Did I do something wrong?

Thanks broquaint, but I do not want to store a list. That is a very well written, however over-complicated for this task, bit of code.

Remember, I am looking for the MOST EFFICIENT METHOD. I like any input however. This is more of a learning session for me, all input is valid. Thanks guys!

Replies are listed 'Best First'.
Re: Re: Dynamic Settings from Database, $$string help
by Joost (Canon) on May 21, 2002 at 13:47 UTC
    Do you mean that $lastlog should have the value of the last $name? Then you can simply do:

    my (%settings,$name,$value); while ((undef,$name, $value) = sql->fetchrow_array()) { $settings{$name}=$value; } $sql->finish(); print "$name\n";
    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: Re: Dynamic Settings from Database, $$string help
by dsheroh (Monsignor) on May 21, 2002 at 14:33 UTC
    Change the final line of your code to
    print $settings{'lastlog'} . "\n";
    and you should see the results you expect.

    Yeah, it's a little more typing than what you sound like you're used to, but it's more than worth it. There is a technique in perl for using a variable as a variable name, but, as was mentioned earlier, it's bad, bad ju-ju. You don't want to get in the habit of going there, because as soon as you do, somebody's going to put the row 23, sql, MUHAHAHAH! into your database and clobber the query you're trying to read data from.