Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] Why autodie?

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Marc Chantreux <address@concealed>
  • To: IKEDA Soji <address@concealed>
  • Cc: address@concealed
  • Subject: Re: [sympa-developpers] Why autodie?
  • Date: Tue, 27 Feb 2018 09:09:38 +0100

hello Soji,

On Thu, Feb 22, 2018 at 11:42:28PM +0900, IKEDA Soji wrote:
> >> So as a typical use case when I open a file and it doesn't exist with
> >> autodie?
> >
> >> if (open (...)) {
> >> found ... proceed
> >> } elsif ( "File not found" ) {
> >> sure, we look elsewhere
> >> } else {
> >> log the error and handle the problem
> >> }

trying to write an example for this case, i spot that $! doesn't
survive to the eval block so it's lost if you want to do something in
the catch block for example.

so when you want to explicitly handle error, the best way seems to be

no autodie

once again: this is very similar to

use strict

to make perl care about errors for you and

no strict

when you think you will exactly know what to do

use Sympatic;
use autodie;

fun open_r ( $path ) {

no autodie;
my $fh;

return $fh if
open $fh
, '<'
, $path

return another_path
if $!{ENOENT};

handle_the_problem;

}







Archive powered by MHonArc 2.6.19+.

Top of Page