Is there a line length limit for text files created from Perl?

前端 未结 7 1305
栀梦
栀梦 2021-01-12 08:12

While writing a Perl script, I got a requirement to write the user names with comma separation in only one line of the file.

That\'s why I would like to know is ther

相关标签:
7条回答
  • 2021-01-12 08:25

    I just came across such a problem with a line about 1M chrs long in Kwrite.

    Though there is no theoretical limit, if you are to work on you file, you'll have to have the line wrapped to display width. At every edit, many calculations are performed, perchance involving swap memory. Thar makes editing clumsy. Long lines may be quite inconvenient.

    0 讨论(0)
  • 2021-01-12 08:26

    There is no size limit except your filesystem's which is most probably 2TB or something.

    0 讨论(0)
  • 2021-01-12 08:26

    No, there is no such limit until you hit any file-size limits.

    0 讨论(0)
  • 2021-01-12 08:27

    On some old Unix systems, some text utilities (e.g. join, sort and even some old awk) have a limit on the maximum line size. I think this is the limit of utilities but not the OS. GNU utilities do not have such a limit as far as I know and therefore Linux never has this problem.

    0 讨论(0)
  • 2021-01-12 08:38

    Text files are just like any other files and newline character is like any othe character, so only the usual filesize restrictions apply (4Gb size limit on older file systems, file must fit on the disk etc.)

    You won't encounter any problem reading and writing it, unless you're reading it line by line—you can run out of memory then or encounter a buffer overflow of sorts. This may happen in any text editor or text processing program (such as sed or awk), because, unlike OS kernel, in those line separation matters

    I would suggest keeping one user per line, as it's more natural to read and less error-prone when you process the file with an external program.

    0 讨论(0)
  • 2021-01-12 08:43

    The only thing you need to worry about is the size of the file that you can create and the size of the file that you can read.

    Computers don't know anything about lines, which is an interpretation of the bytes in a file. We decide that there is some sequence of characters that demarcate the end of a line, and then tell our programs to grab stuff out of the file until it hits that sequence. To us, that's a line.

    For instance, you can define a line in your text file to end with a comma:

     $/ = ',';
    
     while( <DATA> )
        {
        chomp;
        print "Line is: $_\n";
        }
    
     __DATA__
     a,b,c,d,e,f,g
    

    Even though it looks like I have a single line under __DATA__, it's only because we're used to books. Computers don't read books. Instead, this program thinks everything between commas is a line:

    Line is: a
    Line is: b
    Line is: c
    Line is: d
    Line is: e
    Line is: f
    Line is: g
    
    0 讨论(0)
提交回复
热议问题