spie287 has asked for the wisdom of the Perl Monks concerning the following question:
I have a piece of code that parses this data structure to get the value( { col1 =>value1 col2 =>value2 col3=>value3|value4 col4=>value5|value6|value7 }, { col1 =>value8 col2 =>value9 col3=>value10|value11|value12 col4=>value13|value14|value15 } { col1 =>value16|value17 col2 =>value19|value18 col3=>value20 col4=>value21 } )
This would result me in the same value printing over n over for the number of columns present in each hash (ie 4 in our case). My question is how can I access different col for the DBI insert but without having to go through lot of for loops? And is there a way to check if the value has more than one values and pushing them to array instead of having to get all of them in an array? OR is this good to have the DBI inserts to a different sub routine and pass jus the required column values in an array? Please help. Thanks in advance.foreach my $results (@$hash_of_excel){ for my $colname( sort keys %$results){ my @array = split /\|/,$results->{$colname}; foreach my $value (@array){ warn $results->{'col1'}, $results->{'col2'},$results->{'co +l3'}; last; } } last if $counter++ == 2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: logical solution for a array of hash
by choroba (Cardinal) on Feb 12, 2015 at 22:50 UTC | |
|
Re: logical solution for a array of hash
by Perlbotics (Archbishop) on Feb 12, 2015 at 23:09 UTC | |
|
Re: logical solution for a array of hash
by Anonymous Monk on Feb 12, 2015 at 22:53 UTC | |
by spie287 (Novice) on Feb 13, 2015 at 14:39 UTC | |
|
Re: logical solution for a array of hash
by GotToBTru (Prior) on Feb 12, 2015 at 23:07 UTC | |
|
Re: logical solution for a array of hash
by martin (Friar) on Feb 12, 2015 at 23:00 UTC | |
|
Re: logical solution for a array of hash
by shmem (Chancellor) on Feb 13, 2015 at 22:35 UTC |