cdumont wrote:
> In japanese it could even be :
>
>     wa {
>       '' no baai ni { ... }
>     }
>
> Getting rid off the thema or I guess here taking $_ as the default.
>
> is this possible : 
>
> given $operator {
>     '' {}
>     '' {}
> }
>
> ?
>
>   
If Larry doesn't mind me elbowing into the conversation... The
unmentioned detail here is that given and when are decoupled; they're
not two keywords in the same construct. In other words, given can be
used without when and when can be used inside any block.

C<given> only binds $_ and executes a block, it's kind of a single-shot
C<for>. So you can do this:

given $long_expression_that_is_difficult_to_type_more_than_once {
.trim;
s:g/<!alpha>//;
.prettify;
.indent;
say $_;
}

And C<when> simply matches the current $_ with its argument. So you can,
for example, use it inside C<for> or C<map>:

@encoded = map @list:{
when 'black' { 1 }
when 'white' { 2 }
when /#(.*)/ { $<1> }
}

Miro

Reply via email to