in reply to Pushing at Array of Arrays
The "errors" are warnings. "A" and such evaluate to zero in a numeric context so your labels are pushed on to the first or zero-eth element of your data array. Since people don't usually want to convert "B" to 0, the warning is issued.
The $item index to $data in this line causes the warnings:
push @{$data[$item]}, $labels{$item};
Likely you want something like the below.
I admire the steadfastness I see in your coding effort.
Be well,
rir
#!/usr/bin/perl use strict; use warnings; use diagnostics; my @data = ( # note parens not square brackets '17-02-2005','18-02-2005','19-02-2005', '20-02-2005','21-02-2005','22-02-2005', '23-02-2005','24-02-2005' ); my %labels = ( 'C' => [0,0,0,0,7,0,0,2], 'A' => [0,0,0,0,0,0,5,4], 'B' => [0,0,0,0,0,0,0,0] ); foreach my $key (sort {$a cmp $b} keys %labels) { push @data, $labels{$key}; } use Data::Dumper; print Dumper @data; __END__ $VAR1 = '17-02-2005'; $VAR2 = '18-02-2005'; $VAR3 = '19-02-2005'; $VAR4 = '20-02-2005'; $VAR5 = '21-02-2005'; $VAR6 = '22-02-2005'; $VAR7 = '23-02-2005'; $VAR8 = '24-02-2005'; $VAR9 = [ 0, 0, 0, 0, 0, 0, 5, 4 ]; $VAR10 = [ 0, 0, 0, 0, 0, 0, 0, 0 ]; $VAR11 = [ 0, 0, 0, 0, 7, 0, 0, 2 ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pushing at Array of Arrays
by Miguel (Friar) on Feb 25, 2005 at 11:50 UTC |