in reply to Re^4: head truncate
in thread head truncate

Your fixes were the ones that came to mind when the issue first occured to me. However, I spent a while to come up with a different approach because I don't like that version for two reasons, detailed in Dominus' "red flag" articles.

eof tries to read a byte from the handle, then rewinds the file. Basically, it's a kludge.

Also, you need to set an $eof flag before copying, then check it later. Flag variables are not integral to the algorithm at hand and usually mean the implementation is not a natural way to express that algorithm.

I updated my second post to fix the problems you mentioned. Only cosmetics this time, luckily.. :-)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^5: head truncate
by sauoq (Abbot) on Sep 14, 2002 at 00:35 UTC
    eof tries to read a byte from the handle, then rewinds the file. Basically, it's a kludge.

    Yes, eof is a kludge. But it's also a supported language feature. Using it only required the addition of a line of code and a small change in another. Rather than figuring out how to eliminate it, I chose to spend my time adding error checking to the input. ;-)

    I do like your algorithm better though. ++

    Update: Putting your open in the unless block changes the scope of your $fh variable though. It'll be lexical to the unless block.

    -sauoq
    "My two cents aren't worth a dime.";