Perl 6 An Introduction to Perl 6 #26

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