in reply to Re: conditional catch-blocks 'try {} catch(COND) { }'
in thread conditional catch-blocks 'try {} catch(COND) { }'

I think there are many arguments to be made in favor for using sub _ {} as syntactic sugar, but I forgot one of the most important:

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

Replies are listed 'Best First'.
Re^3: conditional catch-blocks 'try {} catch(COND) { }'
by Fletch (Bishop) on Sep 21, 2021 at 01:04 UTC

    Ah, valid point. Still slightly wary of . . . overloading the single _ with syntactic meaning but it does at least look cleaner than the properly comma'd code. Objection weakened at the least.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.