in reply to Data in Hash - DBI

1
return \%hash (Note the slash)

2
I'm not sure what you mean with "testing the contents", but Data::Dumper does a nice job of printing out the contents for you.

3
I admit to not having entirely read perldoc DBI (ar0n ducks, thusly avoiding any DBI manuals thrown at him...) so I'm not aware of any such function. But this should work:
my $place_holders = "?," x keys %hash; chop $place_holders; my $sth = $dbi->prepare("INSERT INTO my_lovely_table (".join(",", sort + keys %hash).") VALUES ($place_holders)"); $sth->execute( @hash{ sort keys %hash } );

Note though, that the keys in your hashes in your code refer to anonymous arrays (push @{ $hash{$arg} }, split;), so the above won't work with those hashes.

[ar0n]

Replies are listed 'Best First'.
RE: (ar0n) Re: Data in Hash - DBI
by Limo (Scribe) on Oct 01, 2000 at 03:53 UTC
    Thanks for your response. Sorry. What I mean by "testing contents" is, being a new programmer, I often slide in print statements in my code as I build it, to make sure that variables/data structures are getting populated the way I want them to. So, I'm trying to do the same, before I tackle passing the output of the program to DBI (if poss.as you noted). Also, I've got to read some more on DBD::CSV. I'm not sure that it supports "join()". UPDATE: Before the --'s start to really flow, what I meant was "join tables", which is a database function. I don't believe that DBD::CSV has that functionality.