CadGuyExtraordinaire
Programmer
Hi,
I dont know if I'm just staring at this wrong, but it looks like a bug to me...
'map' is supposed to go through a list and perform an expression on each element and return the new list with the result...
@nums=(1,2,3);
foreach $n (@nums) {print "init: $n\n"}
@nums_plus_one=map {$_++} @nums;
foreach $n (@nums) {print "should_be_init: $n\n"}
foreach $n (@nums_plus_one) {print "should_be_plussed: $n\n"}
produces:
init: 1
init: 2
init: 3
should_be_init: 2
should_be_init: 3
should_be_init: 4
should_be_plussed: 1
should_be_plussed: 2
should_be_plussed: 3
why is it modifying the input list and not returning the result to the output list??
I dont know if I'm just staring at this wrong, but it looks like a bug to me...
'map' is supposed to go through a list and perform an expression on each element and return the new list with the result...
@nums=(1,2,3);
foreach $n (@nums) {print "init: $n\n"}
@nums_plus_one=map {$_++} @nums;
foreach $n (@nums) {print "should_be_init: $n\n"}
foreach $n (@nums_plus_one) {print "should_be_plussed: $n\n"}
produces:
init: 1
init: 2
init: 3
should_be_init: 2
should_be_init: 3
should_be_init: 4
should_be_plussed: 1
should_be_plussed: 2
should_be_plussed: 3
why is it modifying the input list and not returning the result to the output list??