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

Hi, My question is regarding storage capacity of a single variable(i.e $dummy).How much a variable can store in perl (i.e. How many Bytes..) or there is no restriction on variable?? Thanks (New user of perl)

Replies are listed 'Best First'.
Re: Limitation On Variable
by arturo (Vicar) on Feb 16, 2001 at 02:42 UTC

    With respect to scalar (string) length, the only limitation you're likely to run into is your system's memory. Same for hash and array sizes:

    Perl stores strings as sequences of bytes, with no arbitrary constraints on length or content

    Programming Perl, p. 38

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: Limitation On Variable
by dws (Chancellor) on Feb 16, 2001 at 02:55 UTC
    Assuming you have the virtual memory available, you might run into problems near 2^31 bytes. One of my more perverse scripts regularly has a 125Mb string. No problems other then swapping.
Re: Limitation On Variable
by Yohimbe (Pilgrim) on Feb 16, 2001 at 03:09 UTC
    Reminds me of the standard recipe for a memory subsystem excerciser in perl.
    Basically only tests ulimit, and the efficiency of your operating system's out of memory performance. and as all these things are, use with extreme caution on systems that you don't admin.
    I've used it to clean ram up so that performance tests that need a cold buffer cache have some free ram to work with.
    perl -e ' while (1) { $x .= " " x 1024 };'

    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
Re: Limitation On Variable
by ColonelPanic (Friar) on Feb 16, 2001 at 03:58 UTC
    If you're talking about numeric data, there are system dictated limits for the size of numbers you can use in calculations. If you want to deal with huge numbers, look into the Math::BigInt and Math::BigFloat modules. I think they are part of the standard distribution.

    When's the last time you used duct tape on a duct? --Larry Wall