perl - Open existing file or make a new one with different name -
in perl script, need open specific file, if file not open (is corrupted, etc.) need make new file new name. if can't make new file, should die out because wrong. here pseudocode of want do:
if (!(open $testfile, q{>>}, "c:\foo\bar\log.csv")) { open $testfile, q{>>}, "c:\foo\bar\log1.csv"; } if (!$testfile) { die $!; }
how can "try-catch" type of behavior in perl?
one of million ways it:
my $fh; open $fh, '<', 'c:\foo\bar\log.csv' or open $fh, '<', 'c:\foo\bar\log1.csv' or die 'can not open file!';
Comments
Post a Comment