Fellow Monastians:
As I pull in records from a flat, tab-delimited file, I parse it into an AoH, one array element for each record (I have to go through this preliminary step because I have to test a few of the hash values for legitimacy).
In the end, I loop through the array and copy each of the hashes into a single hash for insertion into my DB table.
I thought I could do this in just one step:
for ( 0 .. $#fields) { %sql_data = $fields[$_]; ... insert into DB ... }
but even with Data Dumping I couldn't figure out why it wasn't working. So, as a work-around until I could post it here, I did a very convoluted:
for ( 0 .. $#fields) { $sql_data{'description'} = $fields[$_]{'description'}; $sql_data{'billing_code'} = $fields[$_]{'billing_code'}; $sql_data{'user_id'} = $fields[$_]{'user_id'}; $sql_data{'project_id'} = $fields[$_]{'project_id'}; $sql_data{'bad_proj'} = $fields[$_]{'bad_proj'}; $sql_data{'bad_bill'} = $fields[$_]{'bad_bill'}; $sql_data{'bad_user'} = $fields[$_]{'bad_user'}; $stmt = qq/INSERT INTO temp_sheet (/ . join(',', keys %sql_data ) . + qq/) VALUES (/ . join(',', ('?') x keys %sql_data ) . qq/)/; + $sth = $dbh->prepare($stmt); $sth->execute(values %sql_data ); }
I know this could be better, but I just can't make it work. What am I totally not seeing. Thanks in advance.
Yes, I'm using strict.
In reply to Creating a hashes from AoHs by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |