Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why use <$fh> at all?

by blogan (Monk)
on Oct 05, 2002 at 15:55 UTC ( [id://203045]=note: print w/replies, xml ) Need Help??


in reply to Why use <$fh> at all?

Does you test cases include lines that are 15000 characters each or just test cases were the lines are 50 characters each? It's going to make a difference if one read() is going to get 163 lines or one if you need two read()'s to get one line.

Replies are listed 'Best First'.
Re: Re: Why use <$fh> at all?
by cluka (Sexton) on Oct 05, 2002 at 20:48 UTC
    Excellent points! Several people have pointed out very egregious logic errors in the initial code. Several of them are not errors in the sense that I know the specifics of the files I am using (no blank lines, no '\n' at the end of the file).

    I really like blogans comment. Does <$fh> hit the disk each time, or is it reading from a cached block? Does anyone know?

    I guess my initial point was flawed for the general case, but I can reformulate it to a better, stronger statement:

    If you know certain aspects of the files you are reading (e.g. average line size, whether there are blanks in the file, etc) you could implement a bare-bones, lightning-fast read method that passes up the traditional <$fh>. But for a basic, system-independent file-reader, <$fh> is a strong contender.

    Anyone agree?

      Update: a typo and factual error. Mis-read my own benchmark.

      As (was:if) you know your files are not too big to fit in memory and you really need the speed, the add this to your benchmark. It beats your code by 400%60%. Standard perl.

      sub sub3 { open FILE, 'yourfile' or die $!; binmode FILE; my @lines = split $/, do{ local $/; <FILE>; }; close FILE or warn $!; }

      Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://203045]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found