SPUG: Multiple uses of <STDIN> in a script?

Stuart Poulin stuart_poulin at yahoo.com
Thu Oct 14 18:12:45 CDT 1999


One thing you can do on Unix is open /dev/tty for input.
Then even if your program is reading STDIN from a file or a pipe it can get
input from the user.

open(TTY,"</dev/tty") or die "Can't open </dev/tty : $!";

--- Ryan Erwin <ryan at erwin.org> wrote:
> I hate to interrupt our fun discussion on where we are going to have our
> meetings but i ran into a little problem yesterday and wondered if one of you
> know the answer. ;) <- what do ya think of that guy...
> 
> Anyways:
> i have a little command line script on my linux box that takes a list of file
> names on <STDIN>, then asks the user (me) a question about the file. 
> Usually, to get user input I just use my $somevar = <STDIN>; but it doesn't
> work in this case.
> 
> i hunted around last night and found that perlfaq8 had a section called "Why
> can't my script read from STDIN after I gave it EOF?"  This sounds exactally
> like what is happening so I read on and the faq8 said "the POSIX module
> defines clearerr() that you can use."  So I checked the POSIX mod docs and it
> says:
> clearerr - use IO::Handle::clearerr() instead.
> Now, I go over and check IO::Handle docs and find that I'm supposed to issue:
> $fh->clearerr
> I do this (STDIN->clearerr) and it works just find, but I still can't prompt
> the user for something on STDIN.
> 
> The faq8 says that this is the technically correct way to reset the err flag
> so I would like to use it.  Besides, seek on STDIN just seems strange to me
> (if it would even work, i haven't tried).
> 
> Thanks!
> 
> ryan [ryan at erwin.org]
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
>         Email to majordomo at pm.org: ACTION spug-list your_address
> 
> 
> 

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list