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

When writing a Perl script, I had a requirement to write usernames with a comma section in only one line of the file.

This is why I would like to know if there is a limit on the maximum line size in a TXT file.

+6
unix file filesystems perl
source share
7 answers

Text files are like any other file, and a newline is like any character, so only the usual file size restrictions apply (4Gb size limit for older file systems, the file must be inserted on disk, etc.)

You will not encounter any problem when reading and writing, if you do not read it in turn - you may run out of memory or run into a buffer overflow. This can happen in any text editor or word processing program (for example, sed or awk), because, unlike the kernel of the OS, in these matters, line breaks

I would advise leaving one user per line, as it is more natural for reading and less prone to errors when processing a file using an external program.

+12
source share

There is a size limit other than your file system, which is most likely 2 TB or something else.

+3
source share

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

Computers do not know anything about strings, which is the interpretation of bytes in a file. We decide that there is some sequence of characters that delimit the end of the line, and then tell our programs to extract material from the file until it reaches that sequence. For us, this is the line.

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

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

Although it looks like I have one line under __DATA__ , this is only because we are used to books. Computers do not read books. Instead, this program thinks that 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 
+3
source share

No, there is no such restriction until you click on the file size limit.

+2
source share

I encountered such a problem with a line of about 1 million hours in Kwrite.

Although there is no theoretical limit, if you want to work with your file, you will need to wrap the line to display the width. With each editing, many calculations are performed that use swap memory. Tar makes editing awkward. Long lines can be quite uncomfortable.

+2
source share

On some older Unix systems, some text utilities (like join, sort, and even some older 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 has never encountered this problem.

+1
source share
file size

Depends on your OS file system. Tools have no limits for such (or at least I have never seen so far ..)

-one
source share

All Articles