Skip to content

Instantly share code, notes, and snippets.

@colomon
Created July 25, 2014 15:28
Show Gist options
  • Save colomon/c3123119436ad6c7db71 to your computer and use it in GitHub Desktop.
Save colomon/c3123119436ad6c7db71 to your computer and use it in GitHub Desktop.
original code:
sub read-file($filename) {
my $file = from-json($filename.IO.slurp);
CATCH {
default {
$file = [];
$*ERR.say: colored("Unable to read file $filename", "red");
}
}
$file.map({ format-object($_) }).hash; # this line not executed after exception caught
}
Current code:
sub read-file($filename) {
my $file;
{
$file = from-json($filename.IO.slurp);
CATCH {
default {
$file = [];
$*ERR.say: colored("Unable to read file $filename", "red");
}
}
}
$file.map({ format-object($_) }).hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment