Last active
December 21, 2015 09:16
-
-
Save amarnus/161c30fe282871d544d3 to your computer and use it in GitHub Desktop.
Returning from inside an eval expression in a subroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Carp::Assert; | |
sub extractOne { | |
return 3 - 2; | |
} | |
sub returnOne { | |
my $one = 0; | |
eval { | |
$one = extractOne; | |
}; | |
### Remove this section and the assertion below will pass ### | |
### start of section ### | |
if ( $@ ) { | |
print STDERR "Error extracting 1..."; | |
} | |
### end of section ### | |
} | |
assert( returnOne == 1, 'returnOne() should return 1' ); | |
### Fix is to move the return statement outside the eval {} block or to | |
### return the value of the eval {} expression. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment