#!/usr/bin/perl
> use strict;
> use warnings;
>
> my %data = (
>
> south => {
> status => {
> open => { count => 3 },
> pws => { count => 3 },
> wip => { count => 0 },
> hold => { count => 1 },
> 're-open' => { count => 0 },
> pwu => { count => 0 },
> openesc => { count => 0 },
> },
> total_count => 7,
> },
>
> north => {
> status => {
> open => { count => 3 },
> pws => { count => 0 },
> wip => { count => 0 },
> hold => { count => 7 },
> 're-open' => { count => 0 },
> pwu => { count => 0 },
> openesc => { count => 0 },
> },
> total_count => 10,
> },
> );
>
> my @items = qw/ open pws wip hold re-open pwu openesc /;
>
> print join( "\t", "region", @items, "total_count" ), "\n";
>
> for my $region ( sort keys %data ) {
> my $d = $data{ $region };
> print join( "\t", $region,
> map( $d->{ status }{ $_ }{ count }, @items ),
> $d->{ total_count },
> ), "\n";
> }
>
> __END__
>
>
> Output:
>
>
>
Hi Ruud,
I have a table in mysql database. I want to insert the values as row.
north 3 0 0 7 0 0 0 10
south 3 3 0 1 0 0 0 7
I want to insert the above (%data) hash values in mysql data base. For
example, the below code works for me. But I don't know how to make the
(%data) hash to (@dbdata) format.
@dbdata=(
["north" ,'3', '0' ,'0', '7' ,'0' ,'0',' 0',' 10'],
["south", '3',' 3' ,'0' ,'1', '0',' 0' ,'0', '7' ],
)
my $connect = DBI->connect($dsn, $username, $password);
my $query = "INSERT INTO by_region (region,open,pws,wip
,hold,reopen,pwu,openesc,total) VALUES (?,?,?,?,?,?,?,?,?)";
my $query_handle = $connect->prepare($query);
for my $datum (@dbdata)
{
$query_handle->execute(@$datum);
}
How to make the above (%data) hash into below reference :
@dbdata=(
["north" ,'3', '0' ,'0', '7' ,'0' ,'0',' 0',' 10'],
["south", '3',' 3' ,'0' ,'1', '0',' 0' ,'0', '7' ],
)
It will solve my problem. I hope this time I am clear.
Thanks & Rg
Mohan L