Re: 3-argument open on STDIN
- From: Bryan_R_Harris@xxxxxxxxxxxx (Bryan R Harris)
- Date: Tue, 23 Aug 2011 18:25:27 -0500
"Bryan" == Bryan R Harris<Bryan_R_Harris@xxxxxxxxxxxx> writes:
Bryan> How can I use the "safe" 3-argument open and still be able to read
off
a
Bryan> pipe?
You don't. 2-arg open has to be good for something.
And 2-arg open is perfectly safe if the second arg is a literal:
open OTHER, "<-" or die;
open my $handle, "<-" or die;
Don't let anyone tell you "Always use 3-arg open" unless they also
footnote it with "unless you have no variables involved".
Hmm. With this tool if there's a pipe and no user-supplied files, I just
put "-" onto the list of files to search -- using the 2-arg open. Someone
suggested that was a bad idea, so I switched to the 3-arg open but that
broke reading off the pipe.
So is it right that in order to read off the pipe *and* be safe, I have to
have both types of "open" statements in my code?
If your file names aren't hard-coded into the program then yes.
This same question received five replies on 18 August. Did you read
them?
Absolutely, I did -- and I got the script working by having logic that
selects whether to use the 2-arg open or the 3-arg open. But since I had
Randall's attention I thought I'd make sure that was the better thing to do.
Thanks to all for the responses -- a great list!
- Bryan
.
- References:
- Re: 3-argument open on STDIN
- From: Rob Dixon
- Re: 3-argument open on STDIN
- Prev by Date: Re: CPAN on Windows Box
- Next by Date: Re: CPAN on Windows Box
- Previous by thread: Re: 3-argument open on STDIN
- Next by thread: self referential arrays/hashes ?
- Index(es):
Relevant Pages
|