in reply to Re: Re: STDIN following on?
in thread STDIN following on?

Well, try this little test:

eoftest.pl:
#!/usr/bin/perl -w use strict; my @lines = <STDIN>; my $line = <STDIN>; print @lines; print "----\n"; print $line;

Typing in the input from the terminal works great. But here's the problem:

cat file | eoftest.pl

You'll get your uninitialized value warning there. Reason? I think it has to do with the redirection (or to be more correct, piping) of STDIN when running your script. STDIN is now a pipe from "cat file" and can't have anything more read from it - causing the warning.

Update: You may want to do something like this:
open STDIN, "/dev/pts/0";
to reopen STDIN to the correct place.

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re^3: STDIN following on?
by tfrayner (Curate) on Aug 10, 2001 at 23:22 UTC
    Aha! Light dawns. This has the ring of truth about it. I hadn't appreciated the semi-permanent nature of these pipes.
    Thanks!
      You could try doing a close on STDIN, then re-opening it, but I have no idea if this'll work, or if it does, how well.

      ------
      /me wants to be the brightest bulb in the chandelier!

      Vote paco for President!

        Thanks.
        Sadly I just tried this and it doesn't work. The uninitialized value message is still there. Interestingly the error message is slightly different when this approach is applied to Cheeselord's example (which describes the problem well, I think). If I don't close and reopen STDIN, the string '<STDIN> line 6' is appended to the error message. Line 6 is where the first read occurs (i.e. where cat file | eoftest.pl feeds in). I wonder if these pipes are dictated by the parent shell rather than perl itself?

        </musing>