etcshadow has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tieing a local filehandle
by BrowserUk (Patriarch) on Aug 09, 2004 at 18:05 UTC | |
by etcshadow (Priest) on Aug 09, 2004 at 18:15 UTC | |
|
Re: Tieing a local filehandle
by ysth (Canon) on Aug 09, 2004 at 18:37 UTC | |
|
Re: Tieing a local filehandle
by blokhead (Monsignor) on Aug 09, 2004 at 18:23 UTC |