Re: Exit subroutine on filehandle error

2011-07-29 Thread Paul Johnson
On Fri, Jul 29, 2011 at 04:05:26PM +0200, Dr.Ruud wrote: > On 2011-07-28 00:45, C.DeRykus wrote: > > > open( ... ) or warn "..." and return; > > Here you are assuming that warn always returns true. It actually > does, even if the device that it write to is full, but I don't think > that is

Re: Exit subroutine on filehandle error

2011-07-29 Thread Dr.Ruud
On 2011-07-28 00:45, C.DeRykus wrote: open( ... ) or warn "..." and return; Here you are assuming that warn always returns true. It actually does, even if the device that it write to is full, but I don't think that is documented ... -- Ruud -- To unsubscribe, e-mail: beginners-uns

Re: Exit subroutine on filehandle error

2011-07-28 Thread Kevin Spencer
On Wed, Jul 27, 2011 at 9:30 AM, Rob Dixon wrote: > What exactly is wrong with "or do {...}"? > > I believe it is the best option simply because is is comparable to the > common "open ... or die $!" idiom. The do is there only so that a > warning can be issued as well as the return There's nothin

Re: Exit subroutine on filehandle error

2011-07-27 Thread C.DeRykus
On Jul 27, 9:30 am, rob.di...@gmx.com (Rob Dixon) wrote: > ... > > Well, one thing I dislike about it is that it is using "or do {...}" > > instead of > > an "if ( ) { ... }". And I did mention something similar. > > What exactly is wrong with "or do {...}"? > > I believe it is the best option sim

Re: Exit subroutine on filehandle error

2011-07-27 Thread Rob Dixon
On 27/07/2011 08:51, Shlomi Fish wrote: On Tue, 26 Jul 2011 16:58:47 +0100 Rob Dixon wrote: On 26/07/2011 16:39, Nikolaus Brandt wrote: On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: Another option would be to use eval { ... } and $@ to trap exceptions: Thank you all for the

Re: Exit subroutine on filehandle error

2011-07-27 Thread timothy adigun
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

Re: Exit subroutine on filehandle error

2011-07-27 Thread Shlomi Fish
Hi Rob, On Tue, 26 Jul 2011 16:58:47 +0100 Rob Dixon wrote: > On 26/07/2011 16:39, Nikolaus Brandt wrote: > > On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: > >> > >> Another option would be to use eval { ... } and $@ to trap exceptions: > > > > Thank you all for the replies. > > >

Re: Exit subroutine on filehandle error

2011-07-26 Thread Rob Dixon
On 26/07/2011 16:39, Nikolaus Brandt wrote: On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: Another option would be to use eval { ... } and $@ to trap exceptions: Thank you all for the replies. I used the above mentioned eval-$@ solution which was absolutely working fine. I t

Re: Exit subroutine on filehandle error

2011-07-26 Thread Nikolaus Brandt
Hi, On Tue, Jul 26, 2011 at 01:01:54PM +0300, Shlomi Fish wrote: > Hi Nikolaus, > > On Tue, 26 Jul 2011 11:32:19 +0200 > Nikolaus Brandt wrote: > > > Hi, > > > > I'm currently writing a script which contains a subroutine to write > > data to files. > > Currently I use > > open $fh, '>', "$base

Re: Exit subroutine on filehandle error

2011-07-26 Thread John W. Krahn
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 availa

Re: Exit subroutine on filehandle error

2011-07-26 Thread Miquel Ruiz
El 26/07/2011 12:01, Shlomi Fish escribió: Another option would be to use eval { ... } and $@ to trap exceptions: http://perl-begin.org/tutorials/perl-for-newbies/part4/#page--exceptions--DIR Important to remember that "open" won't raise an exception if you are not using the "autodie" pragma

Re: Exit subroutine on filehandle error

2011-07-26 Thread Shlomi Fish
Hi Nikolaus, On Tue, 26 Jul 2011 11:32:19 +0200 Nikolaus Brandt 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 th

Exit subroutine on filehandle error

2011-07-26 Thread Nikolaus Brandt
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