Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created August 8, 2019 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsolomon/e43522deebd71c6539ed12026f82788b to your computer and use it in GitHub Desktop.
Save andrewsolomon/e43522deebd71c6539ed12026f82788b to your computer and use it in GitHub Desktop.
use Perl's eval
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
sub oops {
die "It happened";
}
# Instead of just
#
# say oops();
eval {
say oops();
};
if ($@) {
say "Caught it!";
}
# This code isn't reached without encosing the call to oops() in an eval
say "I got to the end";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment