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 no-no
:-)  I personally liked the s/// for @array expression.


On Thu, 23 Aug 2001, John Edwards wrote:

> 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 finished empty the first
> array and replace with the fixed one. There must be a better way, right....
>
> John Edwards
> IT Support
> Runecraft Leeds
>
> Phone: 0113 2206317
> Fax: 0113 2206301
> Mobile: 07961 356186
>
>
>
> --------------------------Confidentiality--------------------------.
> This E-mail is confidential.  It should not be read, copied, disclosed or
> used by any person other than the intended recipient.  Unauthorised use,
> disclosure or copying by whatever medium is strictly prohibited and may be
> unlawful.  If you have received this E-mail in error please contact the
> sender immediately and delete the E-mail from your system.
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to