Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: How to preserve the value of STDIN

by chromatic (Archbishop)
on Sep 22, 2000 at 03:08 UTC ( #33584=note: print w/replies, xml ) Need Help??

in reply to How to preserve the value of STDIN

If you can copy STDIN before anything reads from it, you might have luck. The following code works for me under Linux:
#!/usr/bin/perl -w use strict; open (NEWIN, "<&STDIN") or die "$!"; open (STDIN, "/dev/null"); print while (<NEWIN>);
I saved it as '' and called it with cat | ./

(Find out about <& at open.)

Of course, you can pass a reference to a typeglob containing the NEWIN fh to the constructor...

Replies are listed 'Best First'.
RE: Re: How to preserve the value of STDIN
by Fastolfe (Vicar) on Sep 22, 2000 at 03:10 UTC
    This is still only a one-shot deal. <STDIN> now immediately returns an EOF (since we're reading from /dev/null now) as will any subsequent read from <NEWIN> (since we've read everything from what was once STDIN). We're not gaining anything here, in other words. He needs his in-house stuff to parse STDIN *as well* as Both of them are written to read from STDIN, and only the first will succeed.

    If this were a normal file handle, we could seek(STDIN, 0, 0) to return it to a sane, starting state, but you can't do this with STDIN, because it's actually more like a pipe than a file.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://33584]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2018-01-19 16:13 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (221 votes). Check out past polls.