in reply to Re^2: Unshift and push inside of map operation.
in thread Unshift and push inside of map operation.
foreach doesn't, but that's an odd thing to say about map since map has nothing to do with arrays. map iterates over a list, and it has no problem working with a list built from an array.
You are assuming a lack of optimizations and levels of optimization are very much subject to change. I strongly suspect that there are older versions of Perl that didn't optimize foreach over a single array. I suspect that there will be future versions of Perl that can optimize map/grep over a single array. Indeed, I'm not convinced that there aren't already versions of Perl that can optimize such (nor have I seen evidence that there are such, but I prefer to not assume things about levels of optimization exactly because they are so subject to change).
It is merely an optimization that makes foreach treat a single array differently than some other list. There is little to stop map or grep from acquiring a similar optimization. So I find it "odd" for you to make such a stark distinction between them.
- tye
|
|---|