http://qs321.pair.com?node_id=1109018


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