develooper Front page | perl.perl5.porters | Postings from June 2015

Re: Question/suggestion on perlfunc.pod example

Thread Previous | Thread Next
Eric Brine
June 19, 2015 22:22
Re: Question/suggestion on perlfunc.pod example
Message ID:
Until now, the documentation for do() had recommended boilerplate that
simplified to:

   or die($@ || $! || "Did not return true");

Aristotle has proposed changing it so we now need

my $rv = do($file);
die $@ if $@;
die $! if !defined($rv) && $!;

Supposedly, it's to support having files return undef. But that still
doesn't work.

$ echo 'unlink("xxxxxxxxxxx"); undef' >x

$ perl -e'
    my $file = "x";

    # Exact code from the patch follows.
    local ($!, $@);
    my $result = do $file;
    if ($@)
       { warn "Couldn'\''t compile $file or exception thrown: $@" }
    elsif ($! and not defined $result)
       { warn "Couldn'\''t read $file: $!" }
Couldn't read x: No such file or directory at -e line 7.

I oppose the change to

my $rv = do($file);
die $@ if $@;
die $! if !defined($rv) && $!;

as it's far far more complex than it needs to be, and there is no benefit.

PS - The proposed patch uses '' in one place and $file in two other
places in the same snippet.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About