in reply to Re: STDIN schizofrenia
in thread STDIN schizofrenia

ACK! My bad for posting untested code. You have to dupe STDERR to pull this off:
open STDERRIN,"<&STDERR" or die "Could not dupe STDERR for input: $!\n +"; my $line = <STDERRIN>;
While STDERR is a file-descriptor to your terminal (if you haven't redirected stdout), it is only an outbound channel... so you need to open an inbound channel to the same device if you want to read from it.

------------
:Wq
Not an editor command: Wq

Replies are listed 'Best First'.
Re: STDIN schizofrenia
by Abigail-II (Bishop) on Oct 13, 2003 at 16:22 UTC
    $ perl -wle 'open STDERRIN,"<&STDERR" or die $!; my $line = <STDERRIN> +' Filehandle STDERRIN opened only for output at -e line 1. $

    Abigail

      [me@host scratch]$ perl -wle 'open STDERRIN,"<&STDERR" or die $!; my +$line = <STDERRIN>; print "YAY!!! $line";' sadf YAY!!! sadf [me@host scratch]$
      WTF? perl version maybe?
      [me@host scratch]$ perl -v This is perl, version 5.005_03 built for i386-linux ...
      I also don't get the warning you posted when running your earlier one-liner.

      ------------
      :Wq
      Not an editor command: Wq
        Seems to be version dependent:
        #!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; my $program = 'open STDERRIN, "<&STDERR" or die $!; my $line = <STDERRIN>; print "YAY!!! $line";'; foreach my $version (qw /5.005 5.6.0 5.6.1 5.8.0 5.8.1/) { print "Version $version\n"; system "/opt/perl/$version/bin/perl -we '$program'"; } __END__ Version 5.005 foo YAY!!! foo Version 5.6.0 bar YAY!!! bar Version 5.6.1 Filehandle STDERRIN opened only for output at -e line 2. baz YAY!!! baz Version 5.8.0 Filehandle STDERRIN opened only for output at -e line 2. Use of uninitialized value in concatenation (.) or string at -e line 2 +. YAY!!! Version 5.8.1 Filehandle STDERRIN opened only for output at -e line 2. Use of uninitialized value in concatenation (.) or string at -e line 2 +. YAY!!!

        It runs on 5.005, 5.6.0 and 5.6.1, although it gives a warning under 5.6.1. It won't read from STDERRIN in 5.8.0 or 5.8.1.

        Abigail