I have a perl program that accepts the input and output arguments of a file, and I would like to support a "-" convention for specifying standard input / output. The problem is that I cannot just open the file name because open(my $input, '<', '-') opens a file with the name - rather than standard input. So I have to do something like this:
my $input_fh; if ($input_filename eq '-') {
And similarly for the output file. Is there a way to do this without testing for a particular case? I know that I could crack the file descriptor ARGV to do this for input, but this will not work for output.
Edit: I was informed that the 2-argument form of open really does the magic I'm looking for. Unfortunately, he also does some creative interpretation to separate the file name from the mode in the second argument. I think the form of the 3-argument open is 100% free of magic - it always opens the exact file that you tell it. I ask if I can have a single exception for "-" , but still handle every other file name explicitly.
Should I just keep my code on top of the subprogram / module and stop whining?
source share