* David E. Wheeler <david@kineticode.com> [2013-07-25 12:45]: > Could you do conditional checks for each catch that way, as Aristotle > suggested? Would it be defined inside the parens, as in: > > my $retry = 0; > while ( $retry < 5 ) { > try { $some->transaction } > catch my $err ( $err->isa('X::Transient') ) { ++$retry } > } > > Seems a *little* weird, but not too bad. I guess global $_ would be > the default just like for? And then if you have multiple `catch`es, then what? catch my $err (this) {} catch my $err (that) {} catch my $err (theother) {}? You just name the variable over and over and over? If you don’t want to, where does the name go? On the `try`? try my $err { $some->transaction } catch ( $err->isa('X::Transient') ) { ++$retry } I mean that’s workable, but the scoping is utterly bizarre. If you want to avoid the scope bizarreness you have two choices: Either you put the `catch`es inside the `try`; then you need a form of phasers and then you realise that generalises to other types and as you start adding more of them you realise that all control flow can be seen a special kinds of exceptions… and you have mutated into Perl 6. Which is to say there is a reason Perl 6 went where it did and if you want to do things really right, in many cases you will find yourself running right after it. Or else you use a global variable to avoid the need for declaration that led you into the mess in the first place. In cases like this I tend to prefer Perl 5 to stay Perl 5 rather than trying to reinvent Perl 6 poorly within the constraints of Perl 5, since if I want Perl 6 I know where I can** find it. ** For values of “can” equal “will eventually be able to”. Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>Thread Previous | Thread Next