Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Adding rows of data

by 2teez (Vicar)
on Dec 02, 2014 at 18:32 UTC ( [id://1109018]=note: print w/replies, xml ) Need Help??


in reply to Adding rows of data

Hi, In MHO, I would have suppose that you push, the data from $data variable into the variable $header_row instead the other way around, using unshift like you are doing. Something like so

... push @$header_row, @$data; print Dumper $header_row; ..
And of course, it gives you the same output like you had previously.
However, to have your desired out something like this works
use strict; use warnings; use Data::Dumper; my $data = _test(); my $header_row; push @$header_row, [ "City Name", "Last Name", "First Name", "Addrress +", ], [ "", "", "", "", ]; my @values = qw(CITY LAST_NAME FIRST_NAME ADDRESS); push @{$header_row} => [ map { @{$_}{@values} } map { @{$_} } @{$data} + ]; print Dumper $header_row; sub _test { my @data = [ { 'CITY' => 'San Frans', 'LAST_NAME' => 'Doe', 'FIRST_NAME' => 'Jonh', 'ADDRESS' => '100 Main Street', }, ]; return \@data; }
Output
$VAR1 = [ [ 'City Name', 'Last Name', 'First Name', 'Addrress' ], [ '', '', '', '' ], [ 'San Frans', 'Doe', 'Jonh', '100 Main Street' ] ];
Since, you said you cannot change the subroutine _test()

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found