Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: Re: Re: desire to pass file handles by value

by ysth (Canon)
on Nov 07, 2003 at 09:52 UTC ( #305259=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: desire to pass file handles by value
in thread desire to pass file handles by value

Nice. It does have negative one side effect, though. If you are reading from some other file (say <STDIN>), and you reference $pos, the tell or seek will change perl's idea of the most recent input file to F. This will mess up the "<STDIN> line n" in any error/warning message, and also change what handle the $. var is looked up in.

To fix this, put a local $.; in STORE and FETCH. (For some reason, this then triggers some warnings from STORE when $pos is localized. Fix by saying seek($pos||0,0)).

If you are downvoting this for other than lack of interest, thanks for sending me a message or reply to let me know why so I can do better (or just stay quiet) next time.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: desire to pass file handles by value
by jdporter (Canon) on Nov 07, 2003 at 16:29 UTC
    Ah, thanks for debugging that. When I tried it on STDIN, I got the fubar, and simply dismissed it with a "What do you expect, seeking back and forth on a non-file stream?" :-)
    But Perl is smarter than I am... as usual.

    The 6th Rule of Perl Club is -- There is no Rule #6.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2021-03-03 18:20 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (86 votes). Check out past polls.