in reply to Opening file and checking for data

I can't see anything wrong with your code, and 'tcf22's example looks fine too. Although I've never used it, for comparing which of a few different ways is most efficient, the 'Benchmark' module might be helpful. Do
perldoc Benchmark
at a command prompt to see how to use it.

HTH.

Replies are listed 'Best First'.
Re: Re: Opening file and checking for data
by hmerrill (Friar) on Jul 03, 2003 at 13:46 UTC
    In the Perl Cookbook recipe 3.9 'High-Resolution Timers' looks pretty useful for timing code - it uses the Time::HiRes module which comes standard in Perl 5.8:
    use Time::HiRes qw(gettimeofday); $t0 = gettimeofday; ### your code here ### $t1 = gettimeofday; $elapsed = $t1 - $t0; # elapsed is a floating point value, representing the # number of seconds between $t0 and $t1
    then do the same thing for the *other* way, and see which one takes the least amount of time.

      If you want to benchmark your code, use Perl's Benchmark module. There's no need to reinvent it. Super Search should find numerous examples of how to use it.

      Update: I see you have already mentioned Benchmark. In future, I must read more carefully before repying. Bad me.