Jim Cromie wrote: > with p5, Ive often written > > eval {} or carp "$@ blah"; > > it seems to work,
....modulo any block that returns false :-( > and it reads nicer (to my eye) than > > eval {}; if ($@) {} > > but I surmise that it works cuz the return-value from the block is non-zero, > for successful eval, and 0 or undef when block dies, not cuz of magical > treatment of $@. No. C<eval> return the last evaluated value in the block, unless an exception is thrown, in which case it returns C<undef>. The problem with the C<eval {...} or whatever> approach is that there are situations in which the block can evaluate successfully but still return C<undef>. On failure, C<eval> sets C<$@>, so careful programmers test it separately. Of course, you *can* do that in a single statment if you want: eval {} or @! and carp "$@ blah"; > I gather that ';' is unneeded in p6, Err...no. > and given that $! is the 'exception'al topicalizer, Only inside an explicit CATCH block. > is this construct no longer reliant on the last value in the eval block ? In Perl 6 C<eval BLOCK> becomes C<try BLOCK> and you'll still be able to write: try { ... } // carp $!; but that will trip up if the final value of the C<try> block is C<undef>. What you want is: try { ... CATCH { carp $! } } > put another way, does the 'topicalizer' reflect the exit condition of > the closure ? Only in a CATCH block. Damian