in reply to Changing array by changing $_?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Changing array by changing $_?
by JavaFan (Canon) on Oct 13, 2008 at 13:56 UTC | |
by repellent (Priest) on Oct 13, 2008 at 17:25 UTC | |
by gone2015 (Deacon) on Oct 13, 2008 at 15:20 UTC | |
by JavaFan (Canon) on Oct 13, 2008 at 15:28 UTC | |
by ikegami (Patriarch) on Oct 13, 2008 at 15:38 UTC | |
by JavaFan (Canon) on Oct 13, 2008 at 17:02 UTC | |
| |
by gone2015 (Deacon) on Oct 13, 2008 at 16:10 UTC | |
by ikegami (Patriarch) on Oct 13, 2008 at 16:23 UTC | |
|
Re^2: Changing array by changing $_?
by ikegami (Patriarch) on Oct 13, 2008 at 14:05 UTC | |
|
Re^2: Changing array by changing $_?
by TGI (Parson) on Oct 14, 2008 at 18:36 UTC |