in reply to Re: pushing into arrays of arrays
in thread pushing into arrays of arrays

Thanks for that, it helped a lot; but I'm in a bit of a confused pickle.

I'm using GD::Graph to draw some graphs. GD::Graph expects the data in the form;
@graphdata=([@array_of_xlabels],[@dataset],[@dataset],other datasets.. +...)

Now, I am trying to do this;
@labels=(array,of,labels) loop loop build @dataset end loop push(@sets,[@dataset]) end loop foreach $se (@sets) @set=$#{$se} ((some processing)) push(@fixed,[@set]) end foreach push(@graphdata,[@labels]) foreach $fi (@fixed) @fixd=$#{$fi} push(@graphdata,[@fixd]) end foreach

with the aim of ending up with @graphdata looking exactly the same as if I had done;
@graphdata=([@labels],[@dataset],[@dataset2])

so, pointers and references and whatnots all over the shop, and I'm getting confused.....

Replies are listed 'Best First'.
Re: Re: Re: pushing into arrays of arrays
by Tomte (Priest) on Mar 05, 2004 at 15:50 UTC

    If I'm not mistaken (I didn't run any code), you are pushing lists with one element (namely the bigest index of the list you IMO intend to push) onto @fixed.

    After that you push a lot of arrays containing only 1 (that is: (1,)) onto @graphdata.

    please use strict!

    try something like this, take the time to notice the differences between your example and this one:

    use strict; my @labels = qw(my one word labels); my @graphdata = (\@labels); my @sets = (); # looping and data building, fillings @sets foreach my $set (@sets) { my $se = []; # process $set into $se push @graphdata, $se; } my $graph; # GD::Graph stuff my $gd = $graph->plot(\@graphdata);

    Try to understand what you are doing, read a lot, debug your code (e.g. use Data::Dumper), read perldata and perlref thoroughly ;-)

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.