Accessing a var assigned inside a try block throws Error : Unknown code ref type given error ''. Check your usage and try again

Viewed 707

I am trying to figure out why that error is thrown here. Shouldn't it just print 0 provided something wrong happens inside the try block and print 10 otherwise ?

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;
use Try::Tiny;

my $test = 0;
try{
    $test = 10;
    my $s = $test /2;
}
catch{
    print $_;
}

print $test;
1 Answers
Related