http://qs321.pair.com?node_id=133747

kiat has asked for the wisdom of the Perl Monks concerning the following question: (strings)

Hi,

Is there a length limit to how long a line of text can be stored in a flat file, without any line breaks? Does having longer lines make perl more error prone, ceteris paribus?

cheers,
kiat

Originally posted as a Categorized Question.

  • Comment on Is there a length limit to a string? In a flat file?

Replies are listed 'Best First'.
Re: Is there a length limit to a string? In a flat file?
by Biker (Priest) on Dec 21, 2001 at 17:53 UTC

    Juerd already answered this from a Perl point of view. I'll answer the file oriented part of the question:

    A file does have no notion of 'lines'. A file is an ordered collection of bytes with specific values. It is the software that reads and/or writes the file that decides what a line is.

    The convention says that in the DOS/Windows world a line is delimited by CRLF and that in the UNIX world a line is delimited by LF. But this is only a convention. (Which is clearly indicted by the fact that DOS and UNIX have different conventions. ;-)

    As long as your file system can cope with it, you can make the file as big as you want. You can thereby store as long a 'line' as you want in the file.

Re: Is there a length limit to a string? In a flat file?
by Juerd (Abbot) on Dec 21, 2001 at 17:08 UTC
    Perl has no string length limit.
    You are only limited by the amount of memory that is available. Fortunately, having long strings does not make perl more error prone. Perl is famous for its great string capabilites.
Re: line of text: is there a length limit?
by archen (Pilgrim) on Dec 21, 2001 at 18:45 UTC
    Just recently I had to make a script to strip html from a page which was generated by someone else's script. I guess they figured it wasn't important to be able to look at the source at all, because there isn't a single line break in the entire file. At 6.5 Megs, that's a long line. I'm not sure if you're actually trying to do something, or if this is a question for the sake of knowledge, but sucking up a (large) file/line all at once usually isn't such a good idea where memory is concerned.

    You can change the line delimiter character in Perl, but that can easily lead to strange side effects elsewhere in a large script. More or less, you would probably be more interested in the read function.

    Originally posted as a Categorized Answer.

Re: line of text: is there a length limit?
by scain (Curate) on Dec 21, 2001 at 19:47 UTC
    Occationally, I will suck whole chromosomal sequences into a single string and when I am done with it, write it out to a file without a single line break. The largest chromosome is chr 1, which is about 270 Mb (that megabases, but megabytes works too). Granted, you have to have a lot of memory to do that, but I don't have memory problems.

    Originally posted as a Categorized Answer.