in reply to Piping input as an option

You can use IO::Prompt:

use strict; use warnings; use IO::Prompt; while( prompt "next: " ) { print "You said '$_'\n"; }

If you save your script as "prompt.pl":

$ cat > test.txt Hello World ^D $ perl ./prompt.pl < test.txt You said: Hello You said: World $ cat test.txt | perl ./prompt.pl You said: Hello You said: World

Update: I missed the point. If you want to perform differently if the input is given in a pipe or not, you can use IO::Interactive:

use strict; use warnings; use IO::Interactive qw(is_interactive); if (is_interactive){ print "interactive\n"; } else { print "piped\n"; }

If you save this script as "interactive.pl":

$ perl ./interactive.pl intereactive $ cat test.txt | perl ./interactive.pl piped $ perl ./interactive.pl < test.txt piped

citromatik

Replies are listed 'Best First'.
Re^2: Piping input as an option
by jkelly (Initiate) on Jul 05, 2007 at 14:59 UTC
    Good catch. Thanks for your insight.

    -jkelly