Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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?

Comment on defeating STDIN redirection
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 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.
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...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-07-26 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (177 votes), past polls