Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Simon (89)

Simon
  simon-use-perl@perlhacker.org
AOL IM: lathosjp (Add Buddy, Send Message)

Busy Man.

Journal of Simon (89)

Friday May 03, 2002
04:36 AM

Idea derived from don't-hackery

[ #4635 ]
use on;
on failure { die "Some test failed\n" }
try {
   if ($a) { ... }
   if ($b) { ... }
   if ($c) { ... }
};
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • idea seems something similar to my Exception::Handler [bulknews.net] (not on CPAN yet). But I like this syntax more ;)
  • Do you think that on failure {...} should be lexically scoped? And stackable?
    use on;

    on failure {die "This block died"}
    try {
        some_test();
    }

    on io_failure {die "I/O failure"}
    try {
       some_io_test();  ## can throw failure / io_failure
    }

    on failure;
    try {
       some_other_test();  ## generic failures s/b fatal, and I/O caught
    }
    • I don't expect on to be related to eval. What I meant is that:

      on failure {die "Test failed"}
      try {
          if ($a) { ... }
          if ($b) { ... }
      }

      should be equivalent to

      if ($a) { ... } else { die "Test failed" }
      if ($b) { ... } else { die "Test failed" }

      But other than that, yes, it should be lexically scoped and stackable. This is quite easy to implement - I'll give the details in my next perl.com [perl.com] article.

      • That's clearer. The use of on and try threw me. I expected on to be similar to on_* is for event handlers, and try to be an wrapper around an exception block.

        EWRONGCONTEXT I guess.

        Overall, it does look cool, even if the keywords tripped me up a bit.