I want to read from the default input if data is piped in or a file is provided, but if nothing is given I would like to supply a default for while(<>)
to execute on.
Pseudocode:
if(!<>){
<> = system("ls | ./example.pl");
}
while(<>){
...
...
...
}
Your "if data is piped in" makes things difficult. It's easy to say
which will operate on "somedefault" if no filenames are given on the commandline — but that means you'll never get the Perl default of reading from stdin if there aren't any filenames on the commandline.
One possible compromise is to use the -t operator to guess whether stdin is a terminal:
Which will use "somedefault" if there are no filenames on the commandline and stdin is attached to a terminal, but it will use stdin if there are no filenames and stdin is redirected from a file or a pipe. This is a little magical (maybe annoyingly so), but does what you asked for.