I tried to write a program in which perl opens one file, but returns to another if this file does not exist or does not open for any reason. Corresponding line:
open(my $fh,"<","/path/to/file") or open (my $fh,"<","/path/to/alternate/file") or die
In the end, I realized that:
open(my $fh,"<","/path/to/file") or open ($fh,"<","/path/to/alternate/file") or die
worked. What is the difference between these two statements, why does the first work not work, and the second is the right way to do this, or is there still a problem with it?
Edit: if that matters, I use perl 5.12 , and the first fails when "/path/to/file" exists. My tendency is that the second open should not start if the first open is successful, so why will $fh be overwritten by the second?
scope perl
Chris
source share