Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Array of Hashes to Hash of arrays for SQL::Abstract

by Skeeve (Parson)
on Mar 18, 2020 at 10:39 UTC ( #11114423=note: print w/replies, xml ) Need Help??


in reply to Re: Array of Hashes to Hash of arrays for SQL::Abstract
in thread Array of Hashes to Hash of arrays for SQL::Abstract

However, I would probably try to loop over $data just once

The disadvantage here is, that you might loose null-values due to missing keys in your data

my $data = [ {a => 1, b => 2, c => 11}, {a => 3, c => 12}, {a => 5, b => 6} ];

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^3: Array of Hashes to Hash of arrays for SQL::Abstract
by Veltro (Hermit) on Mar 18, 2020 at 16:27 UTC

    I think you are right, in such circumstance I think I would use an index:

    Something like:

    for my $i (0..$#{$data}) { foreach ( keys %{$data->[$i]} ) { $columns->{$_}->[$i] = $data->[$i]->{$_} ; } ; }

    Also makes it fairly easy to see what happens:

    $columns->{$_}->[$i] = $data->[$i]->{$_} ; hash------^-------------------------^ array-----------^-------------^
Re^3: Array of Hashes to Hash of arrays for SQL::Abstract
by haukex (Bishop) on Mar 19, 2020 at 09:52 UTC
    The disadvantage here is, that you might loose null-values due to missing keys in your data

    ... which you didn't mention at all in the root node. Changing the specs on us is not nice :-P Is this example you've shown now representative, or are there other edge cases?

      ... which you didn't mention at all in the root node

      You are right. This is because it was obvious to me. I think this happens to every programmer.

      Sorry.

      or are there other edge cases

      None that I know of.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114423]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-09-27 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (142 votes). Check out past polls.

    Notices?