Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2018-05-22 10:32 GMT
Find Nodes?
    Voting Booth?