I have a bit of logic drain I hope I can explain what I am missing and what I want in a more coherent manner. Let me know if I have to add a bit more data or information. I have a excel sheet, which I am trying to load to a database. I have slurped the data in to a array of hashes. the data in the hash looks like this
( { 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 } )
I have a piece of code that parses this data structure to get the value
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; }
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.

In reply to logical solution for a array of hash by spie287

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.