in reply to Re^4: Reassign STDOUT/STDERR contents to a variable
in thread Reassign STDOUT/STDERR contents to a variable

Sorry, I haven't got the foggiest what's going on in your case :)  Honestly. I can't replicate anything similar here.

binmode should not matter, AFAICT.  Do you get any errors when you add ... or die $! to the various open statements?

Replies are listed 'Best First'.
Re^6: Reassign STDOUT/STDERR contents to a variable
by lothos (Novice) on Sep 26, 2009 at 21:11 UTC

    Figured it out. The difference was that in the script that is to be executed via the eval, you can't rely on the special <> anymore it would seem.

    Executing the following code results in printing the PerlIO man page.

    my $script = 'while(<>) { print; }'; close(STDIN); open (STDIN,'<',\my $stdin); my $script_input = 'blah'; $stdin .= $script_input; eval $script;

    Wheras executing this code works fine:

    my $script = 'while(<STDIN>) { print; }'; close(STDIN); open (STDIN,'<',\my $stdin); my $script_input = 'blah'; $stdin .= $script_input; eval $script;

    Any thoughts on how to workaround this? I like <>.

      The bug goes away if you load "use PerlIO::scalar;"
        Confirmed. Thank you.
      It is unrelated to eval, and truly is a WTF moment , and it prints PerlIO.pm.

      I've confirmed on win32 with perl v5.8.9, v5.10.0, v5.10.1

      #!/usr/bin/perl -- use strict; use warnings; close(STDIN); open( STDIN, '<', \my $stdin ) or die "$!\n$^E"; my $script_input = 'blah'; $stdin .= $script_input; while (<>) { print; }
      Apparently, an internal call to open (by an internal call to require) reused fd 0 (since you closed it), and something is referencing fd 0 rather than *STDIN.