But if I drop the untie:#!/usr/bin/perl -l use IO::Scalar; my $x = ""; { local *STDERR; tie *STDERR, 'IO::Scalar', \$x; print STDERR "foo"; untie *STDERR } print STDERR "bar"; print "caught: $x"; __END__ bar caught: foo
(I also find it odd that printing to a tieed filehandle doesn't honor the output record separator ($\)... but I don't care that much).#!/usr/bin/perl -l use IO::Scalar; my $x = ""; { local *STDERR; tie *STDERR, 'IO::Scalar', \$x; print STDERR "foo"; } print STDERR "bar"; print "caught: $x"; __END__ caught: foobar
So question one: what the heck? Do tie and local just not play well together?
And question two: is there a way to do this? (I'd think that my intent here is pretty obvious.) I've tried several variants on the above, and I know that I can just change it so that it evals everything in the local scope (so that I can manually untie afterwards without worrying that an exception broke out of that block and left me no oppportunity to untie). But still I'm curious.
Thanks
------------ :Wq Not an editor command: Wq
In reply to Tieing a local filehandle by etcshadow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |