Hello all,
Whenever possible I use a subset of a project that I am working on to learn some new element of perl. This winds up being a really great way to improve my perl-Foo but can on occaision lead to a massive time sink with no actual result.
Currently I have hit an impasse on my latest 'I wonder if I can do that' and I would like some feedback if possible. I'm trying to open STDOUT to a subroutine reference and I'm intrigued by the fact that it doesn't die but it also doesn't behave the way I had hoped. I also wonder if it's significant that the variable is still a CODE ref even after I use it in the open statement.use Modern::Perl; print "Hello World 1\n"; my $sub_ref = sub{ warn join( ' ', @_ ) . " - this is really bad" }; open( STDOUT, ">>", $sub_ref ) or die "open failed: " . $!; print "Hello World 2"; warn ref $sub_ref;
results in the output
Hello World 1 CODE at CodeTest.pl line 8.
I would like to get
Hello World 1 Hello World 2 - this is really bad at CodeTest.pl line 3 CODE at CodeTest.pl line 8.
Any help or even don't go there's with an explanation would be helpful. I am aware of tee and pipe and although tie seemed intriguing I couldn't get it to tie \*STDOUT to a CODE ref at all.
In reply to open STDOUT to a subroutine reference? by jandrew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |