"be consistent" | |
PerlMonks |
Changing array by changing $_?by johnvandam (Acolyte) |
on Oct 13, 2008 at 12:02 UTC ( [id://716791]=perlquestion: print w/replies, xml ) | Need Help?? |
johnvandam has asked for the wisdom of the Perl Monks concerning the following question: Dear Monks, I came across an unexpected behavior in perl and I would very much like your input on what is happening in my code. I have an array of which I want to check every element against the keys of a hash containing reference data. Because I want to be able to exclude options (genomes in this example) I want to put a '-' in front of genomes I want to exclude later on. The code below is meant to check if I have provided correct genome names and did not misspell them. In the first peace of code I am manipulating $_ in a foreach loop. But somehow this ends up manipulating my array @species. The last element which initially contained '-CIOINT' now contains 'CIOINT', the - is removed. In the code below that I'm doing the same but now I am not manipulating $_. The array is not changed. I am not working with references so I am very curious as to why the array has changed in the first instance. I'm running perl 5.8.8 on a linux machine. Could someone clarify what happens in the first peace of code? I would be very grateful because it's racking my brain! John Below is the isolated code with the faulty and working code in it.
Back to
Seekers of Perl Wisdom
|
|