With this simple module, you can make variables local to a filehandle (like the $= and $~ variables). Use control variables (like $^N or $^Z) to get "true" globals (variables which are in every package).
package Tie::PerFH; my %value; sub TIESCALAR { bless do { \my $x }, shift } sub FETCH { $value{select()}{$_[0]} } sub STORE { $value{select()}{$_[0]} = $_[1] } 1;

Replies are listed 'Best First'.
RE: Filehandle local variables
by merlyn (Sage) on Oct 12, 2000 at 03:33 UTC
      It's just tie()ing.
      use Tie::PerFH; tie $format, 'Tie::PerFH'; @date_info = qw( 12 3 1985 ); $format = '%02d-%02d-%04d'; open FH, ">some.file" or die "some.file error: $!"; select FH; $format = '%02d/%02d/%04d'; printf $format, @date_info; close FH; select STDOUT; printf $format, @date_info;
      Maybe it's less useful than we'd (I'd?) like, but it's here, and it's not going away. :)

      $_="goto+F.print+chop;\n=yhpaj";F1:eval