> It acts as next.
good catch! :)
> But using next in a given/when to end the given would be odd
Yes and no. Your implying that last (which doesn't look odd) couldn't be used because next is possible.
There are many grammatically correct combinations in perl that look odd, so nobody uses them.
UPDATE: consequently full orthogonality would imply allowing multiple args in given(LIST) | [reply] [d/l] [select] |
Your implying that last (which doesn't look odd) couldn't be used because next is possible.
So, then the rule would be "when using when, there is an implied last when used inside a given, but there's an implied next when used inside a for"?
Not sure if that's an improvement.
consequently full orthogonality would imply allowing multiple args in given(LIST)
Uhm, do realize that given(EXPR) evaluates EXPR in scalar context, while for(EXPR) evaluates in EXPR in list context. As such, given(LIST) isn't meaningful. Changing the context means that you break given(@ARRAY).
If you want given to behave exactly as for, write for. I rather have given to be different from for, then given to be another alias for for/foreach.
| [reply] [d/l] [select] |
> So, then the rule would be "when using when, there is an implied last when used inside a given, but there's an implied next when used inside a for"?
No it's always an implied "next", for one-time-loops "next" and "last" just mean the same thing.
BTW: perlsyn already has such a complicated rule:
Every "when" block is implicitly ended with a "break".
and
Instead of using "given()", you can use a "foreach()" loop.
...
On exit from the "when" block, there is an implicit "next".
> I rather have given to be different from for, then given to be another alias for for/foreach.
My intention was to have a "foreach" variant without automatic aliasing of the variable...
> Changing the context means that you break given(@ARRAY).
Yep, it's too late to change "given" now ...
I still prefer avoiding "given/when" at least until I'm smart enough for smart match.
And passing lists of arrays is no problem with \(...)
DB<100> @a=1..3
DB<101> @b=4..6
DB<102> for (\(@a,@b)) {print}
ARRAY(0xa3dcd78)ARRAY(0xa3dcc48)
DB<103> for (\(@a,@b)) {print @$_}
123456
while "given" relies on magic:
So "given(@foo)" is the same as "given(\@foo)"
| [reply] [d/l] [select] |