in reply to Readdir against large number of files
But you might gain a bit if the files are big. In the worst case, you store the entire content in memory. You could also write the inner loop as:
Alternatively, find the start of the line following the last line mentioning STRUC20, then use sysread and syswrite to copy the last part of the file.use Fcntl 'SEEK_SET'; while (<UNMODIFIED>) { if (/STRUC20/) { seek MODIFIED, SEEK_SET, 0 or die; next; } print MODIFIED $_; } truncate MODIFIED, tell MODIFIED or die;
And there's no need to use /bin/mv to move the temp. file. rename will do.
Of course, the MOST efficient way doesn't involve Perl at all.
|
|---|