[EMAIL PROTECTED] wrote:

> I am using activestate version 5.8 on XP with DBI 1.38. I am trying to
> return values into an associative array so that I don't keep needing to
> connect to the database. I am new to perl and DBI is looking like rocket
> science. The code below has been gleaned from the Internet so I am not
> completely sure what is going on.

That probably is not the best way to learn Perl.  Perl supports many idioms, and this 
has the result that much of the code you find will be highly idiomatic.  The code may 
work in its own context, but be very fragile when adapted in an imitative manner, 
without a ground-up understanding of the language.  Better to learn Perl, starting 
from:
#!perl

use strict;
use warnings;

print "Hello, World\n";

Then build up.

> Basically I need to read the values into the array so that they can be
> called anywhere within the script. When I use print " drop folder $queue
> {'cch'}\n";  as a test for a known value i get a nil value.
>
> Any help would be much appreciated.
>
> Cheers
>
> Neill
>
> sqlstatement="SELECT KeyName,[Value] FROM ConfigTable where SectionName
> = 'OPIQ'"; #Select rows from table

Huh?  This doesn't really look like a SQL statement to me.  What is the [Value] doing 
there?

>
>             $sth = $dbh->prepare($sqlstatement);
>                 $sth->execute ||
>                     die "Could not execute SQL statement ... maybe
> invalid?";
>                       while (my $opi = $sth->fetchrow_hashref){
>                                     my %queue = $opi

That is not a valid assignment.  Did you
use strict;
use warnings;
?  These are a must if you want to understand what is happening with your code.  What 
you are doing here is assigning a simple scalar to a hash.  Scalars can only be 
assigned to hashes in pairs.  Instead, you could assign the whole hash:

my %queue = %$opi

which assigns the hash pointed to by $opi to %queue.  That is probably wasteful, 
though, since the whole hash then has to be loaded into a new hash.  Better simply to 
use $opi, and access your fields through the reference, using the arrow notation:
my $address = $opi->{'address'};


>                       };

Can you describe your desired select clearly, preferably in plain language rather than 
code.  If you can explain what you are trying to do with the brackets, we can probably 
show a better, more portable, way to get there.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to