in reply to "Sparse" Array behavior with "for" and "map"
Similarly, for the map, I have:
$ perl -e '$a = [undef, undef, 3]; map {$_++} @$a; print "@$a"' 1 1 4
Which is the expected result. If you want undef values to be ignored, put an explicit test. I.E. $_++ if defined $_; Also, map in a void context?
Update: Well, you're right, if you create your array your way, it is an attempt to modify a non-existant element. I suggest you just not use the map in a void context. Instead of map {$_++} @a; do @b = map {$_+1} @a; which is safer.
|
|---|