[Israel.pm] given/when bug

Shimon Cohen shimoco at gmail.com
Sun Mar 25 18:20:00 PDT 2012


More careful look at the warnings gives a clue:
The range operators evaluated in scalar context,
and the when-s EXPRs are not trying to smart match against $foo at all.

Let the script run on multi lines input,
and it will do other than default.

On Mon, Mar 26, 2012 at 2:07 AM, Shimon Cohen <shimoco at gmail.com> wrote:

> Hi
>
> Im not sure its "normal arrays" in your when-s.
> its seems the parenthesis are part of when syntax,
> and the given statement is equivalent to:
>
> given ($foo) {
>     say 'small' when 1..10;
>     say 'medium' when 11..20;
>     say 'large' when 21..30;
>     default { say 'unknown' }
> }
>
> However, perl -w warn the same for both versions.
>
> Shimon.
>
> On Mon, Mar 26, 2012 at 12:28 AM, ynon perek <ynonperek at gmail.com> wrote:
>
>> Hi All,
>>
>> Started using given/when and accidentally coded this bug:
>> https://gist.github.com/2200399
>>
>> I now know that I need to use an arrayref inside then when-s, but my
>> question - what did perl think I meant with normal arrays ? will the code
>> ever do anything other than default ? how ?
>>
>> Thanks,
>>   Ynon
>>
>>
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://mail.perl.org.il/mailman/listinfo/perl
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20120326/a9bae767/attachment.htm 


More information about the Perl mailing list