Perl 的 eval

沒有把 eval 的 manual 弄清楚,結果中了不少槍... 以這段 code 來說:

#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

sub a {
    eval {
        return 'Inside eval';
    };

    return undef;
}

print Dumper a();

__END__

輸出結果會是 undef,而非 Inside eval,因為:

the value returned is the value of the last expression evaluated inside the mini-program; a return statement may be also used, just as with subroutines.

沒專心看 manual 的結果 XD

不過這還是沒解決我遇到在 eval 裡面仍然會因為 croak 而結束的情況... 再加油吧 :o

This entry was posted in Computer, Murmuring, Programming, Software and tagged , , . Bookmark the permalink.

One Response to Perl 的 eval

  1. taco says:

    再加油吧 :o
    以後要專心看 manual 喔!!

Leave a Reply

Your email address will not be published. Required fields are marked *