Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Array of Hashes to Hash of arrays for SQL::Abstract

by Skeeve (Parson)
on Mar 18, 2020 at 09:16 UTC ( [id://11114419]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $sql= new SQL::Abstract( array_datatypes => 1 );
    
    my $required = {  a => [1, 3, 5],  b => [2, 4, 6],};
    
    my($stmt, @bind)= $sql->insert( testtable => $required );
    
  2. or download this
    stmt:  "INSERT INTO testtable ( a, b) VALUES ( ?, ? )"
    @bind: (
    ...
                6
              ]
            );
    
  3. or download this
    my $data = [
      {a => 1, b => 2},
      {a => 3, b => 4},
      {a => 5, b => 6},
    ];
    
  4. or download this
    # %columns will become the hash of arrays
    my %columns;
    ...
      # push the value foreach column
      push @{$columns{$_}}, $row->{$_} foreach keys %columns;
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11114419]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found