Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi Monks!

I need to merge this data into one dataset, I tried this:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # This is the dump of a sample data and added to $var1 $var2 $var3 my $var1 = [ { 'date' => '2001-06-04', 'number' => '12345', 'amount' => '100.00', 'status' => 'paid', 'type' => 'new' }, { 'date' => '2000-001-02', 'number' => 'xc234', 'amount' => '30.88', 'status' => 'new', 'type' => 'cost' } ]; my $var2 = [ { 'ppay' => 'Smith Doe' } ]; my $var3 = [ { 'deb1' => '0', 'cred' => '0', 'addr' => '100 - Main Street', 'total' => '250.00 usd', }, { 'deb1' => '0', 'cred' => '50.14', 'addr' => '1 - Central', 'total' => '51.00', } ]; my ($data) = {$var1, $var2, $var3}; print Dumper $data;

Result:

Odd number of elements in anonymous hash at merge.pl line 53.
$VAR1 = { 'ARRAY(0x14bd858)' => [ { 'ppay' => 'Smith Doe' } ], 'ARRAY(0x14cb430)' => undef };


I am looking for this data dump:

$VAR! = [ { 'date' => '2001-06-04', 'number' => '12345', 'amount' => '100.00', 'status' => 'paid', 'type' => 'new' }, { 'date' => '2000-001-02', 'number' => 'xc234', 'amount' => '30.88', 'status' => 'new', 'type' => 'cost' }, { 'ppay' => 'Smith Doe' }, { 'deb1' => '0', 'cred' => '0', 'addr' => '100 - Main Street', 'total' => '250.00 usd', }, { 'deb1' => '0', 'cred' => '50.14', 'addr' => '1 - Central', 'total' => '51.00', } ];

Thanks for the help!

In reply to Merge hashrefs into one by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found