Larry Wall wrote:
On Mon, Mar 05, 2007 at 04:13:16PM +1030, Tom Lanyon wrote:
: Sounds like the following will work, but it doesn't seem 'nice'.
:
: for @invoice
: {
:  .process;
:  1;
: } or fail 'No invoices to process';

Still think if there's no invoices it logically should be tested first.
If you don't want to repeat mentioning the array, how 'bout:

    @invoice or fail 'No invoices to process'
    ==> for @() {
        .process
    }

or equivalently

    @invoice or fail 'No invoices to process'
    ==> map {
        .process
    }

all assuming you don't like my original

    for @invoice || fail 'No invoices to process'
    {
        .process
    }

These should work, as long as you don't replace "fail 'no invoices to
process'" with something that returns a non-empty list.

That said, you could:

 {
   for =<> || fail 'no input'
   {
     .process
   }
   CATCH {
     do_something_else if 'no input'
   }
 }

...where the 'no input' string is there only so that failures
generated by .process will propagate correctly.

--

This solution isn't generalizable beyond "for", though: you wouldn't
be able to use it for "while, "until", or "loop", all of which could
potentially follow the logic of "do something special if the loop
fails to run even once".  Hmm...

 while test -> $result {
   do_something;
   FIRST { do_something_else unless $result }
 }

...except that I don't think that FIRST would run unless $result is true.

I suppose that you _could_ write:

 if test {
   repeat {
     do_something
   } while test
 } else {
   do_something_else
 }

You'd be having to spell out the test twice, though.

--
Jonathan "Dataweaver" Lang

Reply via email to