cwalck has asked for the wisdom of the Perl Monks concerning the following question:

Is there a maximum number of sub-arrays in an array of arrays?
I'm building a bar graph with GD and and would like to have an array of 25 arrays. The first has the hour and the subsequent 24 have the number of incoming viruses for a given hour. The structure works for up to 18 subarrays but after that GD produces erratic results. Perhaps the problem is with GD but before I follow that thread...

Replies are listed 'Best First'.
Re: Maximum sub-arrays?
by BrowserUk (Patriarch) on Feb 29, 2004 at 15:44 UTC

    There is no limit (beyond memory) with perl's array, nested or otherwise.

    GD produces erratic results.

    Could you elaborate? Show a little code? You're more likely to get a useful answer if you do.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re: Maximum sub-arrays?
by tinita (Parson) on Feb 29, 2004 at 15:46 UTC
    perl -wle' for (0..100_000) { $array[$_] = []; } print scalar @array' 100001
    so, no, the number of "sub-arrays" is not restricted. perl data structures aren't restricted at all, except for your machine's memory of course. the problem must be somewhere else.
Re: Maximum sub-arrays?
by tilly (Archbishop) on Feb 29, 2004 at 16:53 UTC
    I would look to a data problem. Such as the sub-arrays not being uniform in length.

    I have successfully managed to get GD to produce working bar graphs with hundreds of data points. Other than having to be careful about what order the bars got drawn in, there weren't any major glitches.

      Everyone, thanks for your help. The problem lied in the fact that I had empty sub-arrays. I was trying to anticipate the number of unique viruses coming in. Sometimes I guess right, others not. All I needed to do was start with an array X and then push a new array on to X for each name in the database.
      my @dbData; while (@names = $day->fetchrow_array()) { $name = $names[0]; push my @virus, [@dbData]; }
        Looking at your code:
        my @dbData; while (@names = $day->fetchrow_array()) { $name = $names[0]; push my @virus, [@dbData]; }

        Where did you initialize the values for @dbData? I suspect you wanted something like this instead:
        my @virus = (); while (my @names = $day->fetchrow_array()) { push @virus, [ $name[0] ]; }