in reply to Is map's sub block really being evaluated in list context? wantarray() returns undef..
My first pass assessment would be that maps block doesn't qualify as a sub in the normal sense:
print map{ print wantarray(); (1,2,3) } 1;; Use of uninitialized value in print at (eval 19) line 1, <STDIN> line +11. 1 2 3
It was obviously called in a list context, else the return would be different:
print scalar map{ print wantarray(); (1,2,3) } 1;; Use of uninitialized value in print at (eval 20) line 1, <STDIN> line +12. 3
This implies that the block is not a true sub as far as wantarray is concerned. It is just a block as with:
print do{ print wantarray(); (1,2,3) };; Use of uninitialized value in print at (eval 23) line 1, <STDIN> line +15. 1 2 3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is map's sub block really being evaluated in list context? wantarray() returns undef..
by moritz (Cardinal) on Oct 20, 2011 at 10:35 UTC | |
by BrowserUk (Patriarch) on Oct 20, 2011 at 15:07 UTC |