http://qs321.pair.com?node_id=69899


in reply to (tye)Re: Closing and re-opening the DATA Filehandle
in thread Closing and re-opening the DATA Filehandle

Nope. That doesn't work either. I wrapped your code into a sub, so I could call it multiple times and got:
Testing(some data) at D:\test.pl line 5, <DATA> line 1. Testing at D:\test.pl line 13. Testing(some data) at D:\test.pl line 5, <DATA> line 1. Can't save DATA: Bad file descriptor
Here is test.pl:
sub Tye { my $pos= tell(DATA); chomp( my $x= <DATA> ); warn "Testing($x)"; { my $fh= do { local(*FH); \*FH }; open $fh, "<&DATA" or die "Can't save DATA: $!\n"; close DATA or warn "Can't close DATA: $!\n"; open DATA, "<&=".fileno($fh) or die "Can't restore DATA: $!\n"; seek DATA, $pos, 0 or die "Can't reposition DATA: $!\n"; } warn "Testing"; } Tye(); Tye(); __END__ some data