Instead I was going to advise that you can avoid the aliasing effect by using map and throwing away the output of the mapping, like this:
Grep could be used in the same way.my @species =('HOMSAP','MUSMUS','-CIOINT'); map { /^-?(.+)$/; $_ = $1; unless (exists $refspecies{$_}) { # Species not in list die "$_ is not in the species table\n"; } } @species;
Fortunately, I tried this before posting. map fails in exactly the same way as foreach!
This means that some pretty innocuous code could be flawed. I think I might have used this form a few times in the past:
I've been corrupting @in without realising!?! I should have been using this:@in = qw{a b c -d -e}; @out = map { s/-//; $_ } @in;
Shame that looks so odd )-:@in = qw{a b c -d -e}; map { s/-//; $_ } @out = @in;
--
.sig : File not found.
In reply to Re: Changing array by changing $_?
by wol
in thread Changing array by changing $_?
by johnvandam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |