Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Created June 19, 2012 20:16
Show Gist options
  • Save 2shortplanks/2956282 to your computer and use it in GitHub Desktop.
Save 2shortplanks/2956282 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use 5.016;
use warnings;
use Try::Tiny;
try {
die "Boom Boom";
} catch {
given ($_) {
when (/Boom/) {
try {
die "Shake shake the room"
} catch {
say STDERR $_;
}
}
}
}
# THIS PRINTS OUT "Boom Boom"!
@2shortplanks
Copy link
Author

given introduces lexical $_ which is closed over by the anonymous subroutine passed to catch which obscures the global $_ that the catch routine populates
i.e. it does the wrong thing for horrifically complex reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment