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
In reply to Re: Piping input as an option
by citromatik
in thread Piping input as an option
by jkelly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |