Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: STDIN following on?

by CheeseLord (Deacon)
on Aug 10, 2001 at 22:54 UTC ( [id://103998]=note: print w/replies, xml ) Need Help??


in reply to STDIN following on?

As I understand it, your first input call (w/ <>) is slurping up ALL your data, so that the next read (using <STDIN>) is reading nothing - that's because the first diamond is in list context, so everything gets read until EOF.

Once again, that's just my opinion. I could easily be misunderstanding your problem, but I hope that helps somewhat.

Somewhat unrelated note/Update: It's been said a few times around here that <> isn't a good idea for reading from STDIN unless you're sure you just want the unadorned diamond (which will read in from the files listed in @ARGV and not STDIN). If that's not the case for you (I can't tell from your code), then I'd suggest switching the call, for both clarity and safety.

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re: STDIN following on?
by tfrayner (Curate) on Aug 10, 2001 at 23:03 UTC
    Hmmm...
    The first read of STDIN was supposed to slurp up all the data, and if the second read doesn't occur the script works fine and behaves as it should. The idea was that I then add a new line to STDIN typing on the console for the second read. I wonder if the second read is going back to the beginning of the original input and processing it again? I don't know how this explains the way that $answer appears to be decidedly undef, though...

    Update: :-) Unfortunately, I've tried both <> and <STDIN>, and both give the same result.

      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

        Aha! Light dawns. This has the ring of truth about it. I hadn't appreciated the semi-permanent nature of these pipes.
        Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103998]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found