in reply to Re^2: Most efficient way to print a file?
in thread Most efficient way to print a file?

Really, does it matter? It's like asking the most efficient way to close your car door to minimize the time of your Miami to New York road trip.
  • Comment on Re^3: Most efficient way to print a file?

Replies are listed 'Best First'.
Re^4: Most efficient way to print a file?
by DreamT (Pilgrim) on Jan 05, 2011 at 12:29 UTC
    There is a lot of files that's going to be opened a lot of times, so I just want to be sure that this link in the chain is optimal

    The thing I'm most concerned with is the best way to put the file in the variable. I do it in a clumsy way today.
    open(FILE, "<test.txt"); @myfile = <FILE>; close(FILE); foreach $myrow (@myfile) { $result .= $myrow; } return $result;
    I just want to do that in a better way :-)
      There is a lot of files that's going to be opened a lot of times, so I just want to be sure that this link in the chain is optimal
      So, you want to make sure the most optimal way of closing your car door, because you are going to make a lot of road trips? Even if it's just trips to the shop, it's not significant.
      The thing I'm most concerned with is the best way to put the file in the variable.
      Ah, but where's the printing aspect?

      Anyway, it's faster to read it in one go instead of first putting it in an array, then joining them one line at the time:

      my $text = do {local $/; <FILE>};
      Or you can use sysread, but you'll have to benchmark if that's faster.

      You also may be able to tweak your filesystem/volumemanager/storagemanager to get a better performance. After all, your road trip gets shorter if you make use of tarmac roads instead of dirt roads. Regardless of the car you use, or your driving skills.