Nikolaus Brandt wrote:
Hi,
Hello,
I'm currently writing a script which contains a subroutine to write data to files. Currently I use open $fh, '>', "$basedir/$userdir/$outfile" or die "Can't write: $!\n"; which has the disadvantage, that the whole script dies if e.g. the userdir is not available. Could you give me an advise how to just exit the subroutine if opening the filehandle fails, without exiting the whole script?
Yes, just exit (return) from the subroutine: open my $fh, '>', "$basedir/$userdir/$outfile" or do { warn "Can't write: $!\n"; return; }; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/