why doesn't the following code create an error if the file can't be found inside an eval block
If i add a die statement then i can get the error message from the die statement like soopen(INFH, "<$file")
But the error displayed is my custom error "can't find input file." I wanted to display the system error message but there doesn't seem to be one if you can't find the file when opening it (though you do get an error if you try and do anything with the file later). I was hoping i could put all my 'dangerous' code inside an eval block and this would catch all the system error messages for me. Is it just one of those things that perl lets you do - open a file handle on a non-existent file?eval { open(INFH, "<$file") or die "can't find input file"; }; print "Error $@", "failed" if ($@);
Would you do your error handling for this any differently? I think die statements all over the place diminish code readability myself
thanksIn reply to opening missing file inside eval statement by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |