Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

defeating STDIN redirection

by bcrowell (Acolyte)
on Mar 07, 2002 at 17:45 UTC ( #150067=perlquestion: print w/replies, xml ) Need Help??
bcrowell has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that I'd like to be able to run from the command line like this:
    myscript filename

Well, I have no problem retrieving the filename using @ARGV, but Perl also redirects STDIN to the file as well, which I don't want. I want STDIN to be the keyboard. How do I do this? I tried closing and reopening STDIN, but that didn't work. Can I do something to my #! line to defeat this feature?

Replies are listed 'Best First'.
Re: defeating STDIN redirection
by japhy (Canon) on Mar 07, 2002 at 17:48 UTC
    You're using <>, then. If you want STDIN, specify: <STDIN>.

    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Thanks -- that did it! I didn't realize that <> was anything other than an abbreviation for <STDIN>.
Re: defeating STDIN redirection
by screamingeagle (Curate) on Mar 07, 2002 at 17:53 UTC
    if you have the Camel book , check out the "Functions" chapter -> explanation for the "open" method...good explanation given there...
Re: defeating STDIN redirection
by talexb (Canon) on Mar 07, 2002 at 17:48 UTC
    Are you saying that any keyboard activity while the script is running gets re-directed to the file that you're naming on the command line? What's inside the script?

    I think more information is needed.

    --t. alex

    "There was supposed to be an earth-shattering kaboom!" --Marvin the Martian

      I have to agree, more info is needed, can you post us up some of your script? Usually if you want STDIN to read your input from the keyboard, you could syntax it something like this:

      print "What do you want to break today?: "; chomp( $command = <STDIN> );

      Just as a crude example. Can we please see some code?

      -- Yes, I am a criminal. My crime is that of defyance.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://150067]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2016-10-21 18:12 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.