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

What is the maximum amount of information stored in an array? Can you increase the size of an array? I tried to store 7000 names in an array at one time but was unsuccessfull. Any ideas?

Replies are listed 'Best First'.
Re: Storing data in Array
by lhoward (Vicar) on Aug 16, 2000 at 20:40 UTC
    Perl lists scale dynamically to fit the amount of data you stick in them. The amount of data you can stick into a list is limited only by the amount of memory you have available. I have used perl lists with millions of entries and never had a problem. You may want to see my Shift, Pop, Unshift and Push with Impunity! post for a look at the performance characteristics of perl lists.

    I doubt your problem is really with a full list. Why don't you post your code so we can see if we can figure out what the problem is?

      Thank you for the quick reply. I made a mistake in writing the question. Actually, I was actually inquiring about the maximum size of variable and increasing its size but instead wrote an array. Would you be kind enough to shed some light on this? Thank You!
        So what you're after is the maximum size of a scalar variable? (what other languages would call a string, although perl's scalars also handle numeric data)

        Scalars (like all perl datatypes) expand and contract dynamically to fit the amount of data you try to stick in them. I have used large scalars before with no problems. I just ran some quick tests on my system and stuck a 10MB chunk of data into a scalar and perl didn't even break a sweat.

Re: Storing data in Array
by bliz (Acolyte) on Aug 16, 2000 at 23:36 UTC
    is there a max size of a scalar? i'm pretty sure it too is dynamically growable as needed... it's not necessarily pretty or effecient when it gets that large.. but I've never run into a size limit with vars/scalars....
      No. "fills available memory" is more likely to be your upper bound than any arbitrary "power of two minus one" that most other languages limit you at.

      The only common limit you may bump into is the length of a Perl identifier. 255 characters before Perl 5.6, and lifted to unlimited in 5.6!

      -- Randal L. Schwartz, Perl hacker

      Actually I have been very impressed with how efficient Perl is on performance. Memory, well that is another story. But try this:
      foreach (1..1000000) { $str .= "hello\n"; }
      Now try its equivalent in another language, like C++, JavaScript, etc.

      Impressed yet? You should be!