Next Making Programs Faster 106

Devel::SmallProf

      % wc myin.dat 
      1568    5707   44808 myin.dat
      % perl -d:SmallProf copy1.pl
      % wc myin.dat 
      1466    5215   40357 myin.dat
      % cat smallprof.out
             ================ SmallProf version 0.9 ================
                              Profile of ./copy1.pl                     Page 1
        =================================================================
     count wall tm  cpu time line
         0 0.000000 0.000000     1:#!/usr/bin/perl
         0 0.000000 0.000000     2:
         1 0.000186 0.000000     3:open IN, "myin.dat" or "die: $!";
         1 0.000196 0.000000     4:open OUT, ">myout.dat" or "die: $!";
      1570 0.013959 0.270000     5:while (<IN>)
      1569 0.015762 0.270000     6: { print OUT $_ unless (/^#/);
         0 0.000000 0.000000     7: }
         1 0.000239 0.000000     8:close OUT;
         1 0.000054 0.000000     9:close IN;
         1 0.000304 0.000000    10:rename "myout.dat", "myin.dat";

But this opens two files and does a rename. I suspect this won't be very efficient.
Is there a better way? Thanks for any advice.


Next Copyright © 2003 M. J. Dominus