Another thing to note about given ... when: you don't have to use them
together.  All that "given" does is to set $_ to the variable
provided; this can be used in a manner similar to "with" statements in
other languages.  And "when" doesn't have to be inside a "given"
block, either: it can be used in any block that sets $_.  For example:

  for @list {
    when *..^0 { say "$_ is negative" }
    when 0 {say "$_ is zero" }
    when 0^..* { say "$_ is positive" }
    default { say "$_ is something else" }
  }

or (I think):

  method test ($value) {
    setup();
    when $value { doit() } #[smart-match the calling object $_ against $value.]
  }

(Question: assuming that the above is valid, would breaking out of the
when block be the same as returning from the method?  Or would it
qualify as an abnormal termination of the method?)

-- 
Jonathan "Dataweaver" Lang

Reply via email to