Hello Nikolaus Brand,
You can try these:
1. ) Instead of "die" in your code use "warn", then return from the
subroutine,
2.) Intstead of hard coding the path and file in your program i.e
["$basedir/$userdir/$outfile" ], ask the user to input the path and file,
assign the input to a scalar and check if it exists/correct or not.
 If the path is correct, then proceed into your subrotine and if not, you
ask the user to check their input and try again! I think that will be a
better way to go!
thanks

On Tue, Jul 26, 2011 at 10:32 AM, Nikolaus Brandt <nickol...@freenet.de>wrote:

> Hi,
>
> 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?
>
> Thanks in advance.
>
> Nikolaus
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to