Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Adding rows of data

by 2teez (Vicar)
on Dec 02, 2014 at 18:32 UTC ( #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; }
$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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2021-04-22 18:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found