in reply to Re: Re: STDIN schizofrenia
in thread STDIN schizofrenia

$ perl -wle 'open STDERRIN,"<&STDERR" or die $!; my $line = <STDERRIN> +' Filehandle STDERRIN opened only for output at -e line 1. $

Abigail

Replies are listed 'Best First'.
Re: Re: STDIN schizofrenia
by etcshadow (Priest) on Oct 13, 2003 at 19:26 UTC
    [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

        Cool. Well, the better way is to try to open /dev/tty, anyway (which I referenced in the original post, too). I was just going off of "use STDERR as a reference to the controlling terminal" notion that is used in many tools... like vim, for example, when you pipe the file to edit in off of STDIN.
        [me@host scratch]$ ptyexec man vim | grep stdin - The file to edit is read from stdin. Commands are +read from stderr, which should be a tty. [me@host scratch]$

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