in reply to Re: Re: desire to pass file handles by value
in thread desire to pass file handles by value
Now if only you could localize a variable that represents the file position, you wouldn't have to manually save/restore its value. Hmmm....
Test:package Tie::Scalar::FHPos; use FileHandle; sub TIESCALAR { my( $pkg, $fh ) = @_; bless [$fh], $pkg; } sub FETCH { my( $self ) = @_; $self->[0]->tell } sub STORE { my( $self, $pos ) = @_; $self->[0]->seek($pos,0); }
Cool!open F, "< foo.dat"; our $pos; tie $pos, 'Tie::Scalar::FHPos', \*F; { local $pos = 20; print "$pos: ", scalar(<F>); } print "$pos: ", scalar(<F>);
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: desire to pass file handles by value
by ysth (Canon) on Nov 07, 2003 at 09:52 UTC | |
by jdporter (Paladin) on Nov 07, 2003 at 16:29 UTC |
In Section
Seekers of Perl Wisdom