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

Re: Question/suggestion on perlfunc.pod example

Thread Previous | Thread Next
From:
Eric Brine
Date:
June 19, 2015 22:22
Subject:
Re: Question/suggestion on perlfunc.pod example
Message ID:
CALJW-qFw_-Thq-nqYtBZYWVBargfxWwgGpSVt+sS8C1+qQCo9Q@mail.gmail.com
Until now, the documentation for do() had recommended boilerplate that
simplified to:

do($file)
   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 'stat.pl' in one place and $file in two other
places in the same snippet.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About