Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: array of hashes?

by AnomalousMonk (Canon)
on Oct 27, 2013 at 15:16 UTC ( #1059914=note: print w/replies, xml ) Need Help??

in reply to array of hashes?

... assistance on how I could ... print this data structure ...

A way to better print the data structure during development and debug (and when communicating with your fellow monks) is to properly use structure dumping tools like Data::Dumper and Data::Dump. For instance, you show one dump as

$VAR1 = 'mode'; $VAR2 = { 'type' => ' auto mode', 'action' => ' completed on own.' };
which suggests a statement like
    print Dumper %hash;
was used to generate it. This use of Dumper and its siblings and cousins such as dd in Data::Dump flattens out the top-level key/value pairs of the hash into a representation that quickly becomes incomprehensible, IMHO, for large structures (although I think dd does a bit better with it than Dumper).

Properly passing the structure by reference leads to a much more comprehensible representation. Ferinstance:

>perl -wMstrict -le "use Data::Dumper; ;; my %component = ( 'mode' => { 'type' => ' auto mode', 'action' => ' completed on own.', }, 'mood' => { 'switch1' => { 'type' => ' auto mode for switch1', 'action' => ' completed with assistance.', }, 'switch2' => { 'type' => ' auto mode for switch2', 'action' => 'completed on own.', }, }, ); ;; print Dumper \%component; " $VAR1 = { 'mode' => { 'action' => ' completed on own.', 'type' => ' auto mode' }, 'mood' => { 'switch2' => { 'action' => 'completed on own.', 'type' => ' auto mode for switch2 +' }, 'switch1' => { 'action' => ' completed with assi +stance.', 'type' => ' auto mode for switch1 +' } } };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1059914]
[perldigious]: A question since I'm ignorant of what's normal for database management... Do admins change column names a lot in databases?
[perldigious]: On occasion my scripts break, because they will do something that seems laregly pointless to me... like in this case, changing a column name from "ABC Category" to "ABC Category Override".
[perldigious]: Being the ignorant one, my initial reaction to that is, "that's sort of a dick move, a lot of people like me expect column names like that to stay the same, why the hell would you change them like that for seemingly no good reason?"
[perldigious]: Or is my irritation/ frustration well founded?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-05-25 13:27 GMT
Find Nodes?
    Voting Booth?