andybshaker has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone, I have the following chunk of code:
foreach $G (@array1){ for $x (0..$#array2){ if($array2[$x] =~ /$G/){ push(@Coordinates,"$array2[$x]"); } } }
I would expect this to create the array "Coordinates" with every value of array2 that matches array1, but what ends up happening is that the array only contains one value, the last value of array1--which indicates that it gets continuously replaced. How can I fix this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why does every value of the array get replaced?
by toolic (Bishop) on May 27, 2015 at 17:50 UTC | |
by GotToBTru (Prior) on May 27, 2015 at 18:27 UTC | |
|
Re: Why does every value of the array get replaced?
by GotToBTru (Prior) on May 27, 2015 at 18:37 UTC | |
by andybshaker (Novice) on May 27, 2015 at 18:46 UTC | |
by toolic (Bishop) on May 27, 2015 at 18:47 UTC | |
by andybshaker (Novice) on May 27, 2015 at 18:58 UTC | |
by GotToBTru (Prior) on May 27, 2015 at 18:59 UTC |