Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: pushing into arrays of arrays

by Crian (Curate)
on Mar 05, 2004 at 12:37 UTC ( [id://334197]=note: print w/replies, xml ) Need Help??


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

Just read the post from xdg above your post again. He just pointed out, that you could use copies in such a case using

push @array, [ @localarray ]

instead of

push @array, \@localarray

Replies are listed 'Best First'.
Re: Re: Re: Re: pushing into arrays of arrays
by Anonymous Monk on Mar 05, 2004 at 12:46 UTC
    Ahhh! Doh! Thanks :)
pushing into arrays of arrays
by Anonymous Monk on Mar 05, 2004 at 12:58 UTC
    Hmm..,

    I'm using the following to read through all of the pushed arrays and list their lengths, but it is returning length -1 each time..
    foreach $ary (@arrays) { print $#{ary}; }


    Grr. :)

      1t Note: $#array is not the length, but the biggest index.

      2nd note:use strict

      #!/usr/bin/env perl use strict; my $ar1 = [1,2,3]; my $ar2 = [4,5,6,7]; my @arrays = ($ar1,$ar2); foreach my $ary (@arrays) { print $#{ary}, "\n"; } __END__ Global symbol "@ary" requires explicit package name at test.pl line 10 +. Execution of test.pl aborted due to compilation errors.

      3d note: Read perldata and perlref! Really, that helps a lot!

      4th note:

      #!/usr/bin/env perl use strict; use warnings; my $ar1 = [1,2,3]; my $ar2 = [4,5,6,7]; my @arrays = ($ar1,$ar2); foreach my $ary (@arrays) { # correct syntax print $#{@$ary}, "\n"; # correct length print scalar(@$ary), "\n"; }

      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.

        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.....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-20 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found