Chaining sub {} requires commas as separators!
Please compare
use strict; use warnings; sub try (&;@) {}; sub catch (&;@){}; sub _ (&;@) {}; sub error_classes { return map { $_ => bless {}, $_ } @_; } use constant { error_classes qw( FileNotFoundError IsADirectoryError ) }; try { # your code here } catch { FileNotFoundError } sub { # handle exception }, # extra comma needed catch { IsADirectoryError } sub { # handle exception }, catch { # all other types of exceptions }; warn ('Should reach here'); try { # your code here } catch { FileNotFoundError }_{ # handle exception } catch { IsADirectoryError }_{ # handle exception } catch { # all other types of exceptions }; warn('Should reach here')
Hence the OP was wrong and needs to be corrected.
If anyone sees a way to avoid the trailing commas (or fat commas), please feel free to show ...
Otherwise, this break in symmetry is just "meh" ...
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re^2: conditional catch-blocks 'try {} catch(COND) { }'
by LanX
in thread conditional catch-blocks 'try {} catch(COND) { }'
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |