Thank you, Leon and Eric.
I knew I missed something :)
Cheers
On 28/01/2011 18:53, Leon Timmermans wrote:
> 2011/1/28 Alberto Simões<albie@alfarrabio.di.uminho.pt>:
>> Consider
>>
>>> #!/usr/bin/perl
>>> use 5.012;
>>>
>>> my $foo = { foo => 1 };
>>>
>>> given($foo) {
>>> when (/oo/) { say "OK" }
>>> default { say "NOK" }
>>> }
>>>
>>> say "OK" if $foo ~~ /oo/;
>>> say "OK" if /oo/ ~~ $foo;
>>
>> I get
>> NOK
>> OK
>> OK
>>
>> but I was expecting the first given/when clause to match.
>>
>> Is this a bug or I missed some piece of documentation?
>
> You missed a piece of documentation «when (/regex/)» is not equivalent
> to «$_ ~~ /regex/» but «$_ =~ /regex/». This is documented in
> perlsyn#Switch-statements as one of the special cases.
>
> I don't know why it works like that though. I'm kind of curious about that.
>
> Leon
--
Alberto Simões
Thread Previous
|
Thread Next