Perl 6 Perl 6 #23

Given / when ('switch' statements)

Example:

given $xyz {
    when 'spot'     { say 'is "spot"';        }
    when /spot/     { say 'contains "spot"';  }
    when Dog        { say 'has type Dog';     }
    when any(@cats) { say 'element of @cats'; }
    when none(@abc) { say 'not in @abc';      }
    default         { say 'unknown';          }
}
Copyright © 2008 Patrick Michaud