I was experimenting with an enumerator function to iterate thru values and indices at the same time.
while this works (>5.10)
sub enum (\@$$){ ... } use feature 'state'; while ( enum @a => state $value, state $i ){ print "enum: $i $value\n"; }
it's not possible to write
while ( enum @a => state( $value, $i ) ){
without getting "a not enough arguments" error.
It's the same for my and our ...
So for what I can see this call tst(my($x,$y))
DB<7> sub tst ($;$) {print scalar @_ } DB<8> tst(my($x,$y)) 1
gets only one parameters passed! (UPDATED example)
So avoiding the syntax error by changing the prototype to make the third one optional - i.e.enum (\@$;$) {} - doesn't help.
That's a parsing error, or do I miss a special reason to handle it this way?
Cheers Rolf
UPDATE: OK I got it, my ($a,$b) seems to be handled like a shorthand for my ($a,$b)=(undef,undef) and therefore just the scalar value of a list assignment is returned.
In other words my returns the number of declared variables...
DB<3> sub tst {print scalar @_ }<P> DB<4> tst( my ($a,$b)) 2 DB<5> tst( my ($a,$b,$c)) 3 DB<6> tst( my ($a,$b,$c,$d)) 4
In reply to why doesn't "my ($a,$b)" return a list? by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |