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

Hi: I wrote a Perl script which would remove the '^L' from the very top of several files. That is, I read the incoming files and if the first line is a '^L' then I ignore it and go to the next line. This works fine for me but sometimes I get a file wherein the subsequent lines are pretty long. So I was wondering, what is the maximum number of characters can Perl hold in a variable? For example, open(INFILE....) while ($line = <INFILE>) { .... } How many characters can $line hold? This is important so that I can assure users that none of their information will be cut off in any case. thanks, daniel

Replies are listed 'Best First'.
Re: Maximum number of characters
by metadatum (Scribe) on Oct 31, 2002 at 20:46 UTC
    as much as the memory of your machine allows...

      ... divided (roughly) by the number of simultaneous proccesses.

        Very roughly, if at all. It depends not only of how much memory those other processes are using, but also on the particulars of the Virtual Memory implementation of the system (if any), the amount of swap space, whether you can overcommit memory etc.

        To get back to the original poster's question: the only limit on the size of a variable in Perl is memory. How much that is in practice is difficult to predict, as fglock's post indicates.

        CU
        Robartes- who will now take of his pedantic hat and quietly shamble off to take a seat in the back of the room again

      Doesn't perl represent the size as a integer or ANSI C size_t variable? Then it would be limited to 4GB or whatever based on a union of your integer size and the integer size of Larry's machine where he may have made assumptions.
Re: Maximum number of characters
by gjb (Vicar) on Oct 31, 2002 at 23:16 UTC

    Why not use a read of one byte? That would circumvent the problem and provide a much nicer solution.

    Your question has been answered by others already ;-)

    Hope this helps, -gjb-