Your @data initially has one element, a reference to an array of date text. Is this what you want? I suspect not. I am guessing your code is only very close to what you want.

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 ];

In reply to Re: Pushing at Array of Arrays by rir
in thread Pushing at Array of Arrays by Miguel

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.