Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

perl

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;
like image 935
Enihr Avatar asked Jan 01 '14 05:01

Enihr


1 Answers

You are missing a ; after the try/catch "statement"; your code is passing the result of the print $test as an extra parameter to catch where it is expecting a finally clause and dies before it even gets into the try block.

like image 154
ysth Avatar answered Sep 24 '22 00:09

ysth