Luke Palmer wrote:
On 1/13/06, Dave Whipp <[EMAIL PROTECTED]> wrote:

Would this actually work, or would it stop at the first elem that
doesn't match ("-f", ::Item)?

If by "stop" you mean "die", yes it would stop.

not what I wanted :-(

Is there some way to associate alternate codeblocks for different
patterns (i.e. local anonymous MMD)?

As Austin points out, that's called "given".  I'll also point out that
if we have lookahead in "for" (a feature that I think is best reserved
for third-party modules):

    for @*ARGV -> $cur, ?$next is rw {
        if $cur eq '-f' {
            $next .= absolute_filename;
        }
    }

Which isn't as slick as a pattern matching approach, but it gets the
job done without having to use indices.

What happens if I simply abandon the attempt at anonymous MMD and use a named multi-sub, instead:

{
  my multi sub process_arg("-f", Str $f is rw) {
     $f .= absolute_filename
  }
  my multi sub process_arg("--quux", Str arg1, Str arg2) { ... }
  ...
  my multi sub process_arg(Str _) {} # skip unrecognised args

  for @*ARGV: &process_arg;
}

Reply via email to