I have a perl program that I want to read from a file passed as an argument or from a pipe. If their is no pipe or arguments, I want it to output a help message. I am stuck on how to prevent perl from reading from the keyboard if it isn't fed any file names or data from a pipe. The only things I can find by searching are tutorials about how to read from files and use the diamond operator.
Here are the relevant lines of the program:
if ($ARGV[0] eq "--help" || $ARGV[0] eq "-h")
{
&help;
}
if ( defined($ARGV[0]))
{
#fill array for sorting
}
else
{
foreach(<>)
my @splitter = split(/\s+/);
foreach(@splitter)
{
if (!/^[0-9]+$/)
{
die("I only like numbers!\n");
}
push (@file, $_);
}
# STDIN and/or file contents get stored in the array @file
if ( ! defined(@file))
{
&help;
}