Hi Rob,

On Tue, 26 Jul 2011 16:58:47 +0100
Rob Dixon <rob.di...@gmx.com> 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.
> >
> > I used the above mentioned eval-$@ solution which was absolutely  working
> > fine.
> 
> I think Shlomi may have been over-thorough in his list of options. 

I've mentioned it for completeness sake.

> Most
> Perl programmers would shudder at the sight of an eval, and in this case
> it is an ugly implementation of the try/catch idiom.
> 

Eh, why? Have you made a survey that concluded that? I agree that eval { ... }
if ($@) in Perl has its limitations but using such abstractions as
http://search.cpan.org/dist/Exception-Class/ , it is good enough. And I think in
this case, it is appropriate because errors should result in exceptions.

> John's
> 
> > open my $fh, '>', "$basedir/$userdir/$outfile" or do {
> >   warn "Can't write: $!\n";
> >   return;
> > };
> 
> (With or without the warning) will do all that you want, and will
> enamour you to all who read your code.
> 

Well, one thing I dislike about it is that it is using "or do {...}" instead of
an "if ( ) { ... }". And I did mention something similar.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

bzr is slower than Subversion in combination with Sourceforge.
    — Sjors, http://dazjorz.com/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
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