JavaFan and others have already given a good explanation of what's going on, so I shalln't repeat them.

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:

my @species =('HOMSAP','MUSMUS','-CIOINT'); map { /^-?(.+)$/; $_ = $1; unless (exists $refspecies{$_}) { # Species not in list die "$_ is not in the species table\n"; } } @species;
Grep could be used in the same way.

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:

@in = qw{a b c -d -e}; @out = map { s/-//; $_ } @in;
I've been corrupting @in without realising!?! I should have been using this:
@in = qw{a b c -d -e}; map { s/-//; $_ } @out = @in;
Shame that looks so odd )-:

--
.sig : File not found.


In reply to Re: Changing array by changing $_? by wol
in thread Changing array by changing $_? by johnvandam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.