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

前端 未结 7 1317
栀梦
栀梦 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: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(  )
        {
        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
    

提交回复
热议问题