Reputation: 73
I am writing a program where if no command line arguments are supplied i.e @ARGV == 0, the program takes in three inputs. But, the program has the feature to read any files given as arguments, thus
calculate input1 input2
runs the formula on the numbers found in file1 and file2.
The problem I am running into is when I run
calculate < input1
@ARGV returns 0, thus it runs the code for user input.
How do I get around this so that the program can read input1 and use the values inside for calculations?
Upvotes: 1
Views: 585
Reputation: 80404
That should not be a problem. If you read reading from <>
(which is really <ARGV>
), then there is no difference.
You must be doing something wrong if redirection changes things. Are you actually opening files yourself???
Upvotes: 2
Reputation: 601
You might consider using a module like Getopt::Euclid or Getopt::Long to make the argument passing more explicit. That might make the program easier to understand for other users too.
Upvotes: 0
Reputation: 943579
calculate < input1
is equivalent to cat input1 | calculate
.
You need to read from <STDIN>
and not look for command line arguments.
Upvotes: 4