When you do a for loop :
for (@array)
{
s/1//g;
}
the implicit $_ in the loop becomes an alias for the real element - so by
modifying the element in the loop you're actually modifying the "real" one
in the array.
Luke
PS you could use map here as well, but it's in a void context - big
August 23, 2001 4:49 PM
| To: 'HOLLAND-MORITZ,MARCUS (A-hsgGermany,ex1)'
| Subject: RE: Strip charactes from every element in array
|
|
| and if the character isn't there
|
| @array(one1 two three1);
|
| I end up with
|
| one tw three
|
| -Original Message-
|
2001 4:45 PM
| To: Perl Beginners (E-mail)
| Subject: Strip charactes from every element in array
|
|
| Is there any easy way to strip a single character from every
| element in an
| array?
|
| @array = qw(one1 two1 three1);
|
| And I need the elements to be (one two three).
|
|
| My only id
Is there any easy way to strip a single character from every element in an
array?
@array = qw(one1 two1 three1);
And I need the elements to be (one two three).
My only idea is copy to another array, run a foreach, s/// the char out and
push into another array, then after the foreach has finish