in reply to Looping over multiple queries

One way of doing that is:
my @names = qw[Center Div Dept]; my %orgs; foreach my $name (@names) { $orgs{$name} = $dbh->prepare("SELECT DISTINCT $name FROM People") +or die; $orgs{$name}->execute or die; }
And if you want to access a single element of an array, better write that as $depts[0] instead of @depts[0].

Replies are listed 'Best First'.
Re^2: Looping over multiple queries
by Mad_Mac (Beadle) on Jan 28, 2010 at 19:35 UTC

    OK, JavaFan, I think you're suggestion works and I *think* I understand it (mostly). Now, my problem is I'm still to much of a noob at handling hash references to know the syntax for extracting the data out of %orgs.

    I could keep plowing through Man Perl and surfing Google ... or you could tell me ;^)

    Thanks again for the tip

      Oops. I spoke too soon. I think I got it:

      while (($k, $v)=each (%orgs)){ while (@k = $v->fetchrow_array()) { print "\t$k[0]\n"; } }

      Unless there's a simpler way?
      Thanks again for the tip :^)

      Now, my problem is I'm still to much of a noob at handling hash references
      That's not a problem.

      However, what is a problem is that you fail to realize my code snippet doesn't use a hash reference at all. There's a hash - not a reference to a hash.

      Perhaps you want to read an introduction book about Perl first?

      Read through perlintro before you try doing anything else , really :)

        Hmmm... Yep, read that a while back. Which is not the same as saying I completely understood all of the important bits. Besides, I'm more of a trial & error, build it first, understand it later, kind of a guy.

        Irritating? Maybe. Inefficient? Probably. But it's the way I'm wired, and I'm way too old to change now.

        Thanks for the tip, tho' :-)