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

I think at least one reason is because <> is line-oriented, in the sense that it scans the data for the next line separater and returns everything before that (well, since the last line separater). On the other hand, read is block-oriented. You tell it how big of a block you want, and it reads in that many bytes. It doesn't look at or scan through the data like <> does. So it depends on how much structure you want. If you want the next line of text, <> does that for you, at the cost of a little speed. If you just want the next n-byte chunk, read is faster. You could try to implement <> with read, but what you'd end up doing is reading in some kind of "reasonable" size chunk and scanning through it for the line separater, throwing the rest away or maybe needing to get the next check to find the end of line. And that method doesn't really have any advantages over just using <> in the first place.

kelan


Yak it up with Fullscreen ChatterBox

Replies are listed 'Best First'.
Re: Re: Why use <$fh> at all?
by cluka (Sexton) on Oct 05, 2002 at 00:49 UTC
    Actually, after I posted the above message I started work on a module that implements <> (via overloading) using read. It still beats the socks off of the traditional <> and gives the "line-oriented" feel back to the user. (The module essentially reads in a 8k block and feeds lines to the user until it needs to read another block...