On 3/22/07, Alan Campbell <[EMAIL PROTECTED]> wrote:

>> true, but I'm tweaking the orig array in-place. So how to modify a given
element if I dont have some index?

With foreach, you don't need an index. The control variable of a
foreach isn't a copy of the array element; it *is* the element of the
array. What you do unto the control variable, you do unto the elements
of the array. If you assign a newline to the control variable, the
array's got a newline; it's a snap.

 my @data = qw{ fred42 barney666 betty90210 wilma007 };
 print "Was: @data\n";
 foreach $item (@data) {
   $item =~ s/(\w+?)(\d+)/$2-\U$1/;
   $item = "pebbles0!" if $2 % 2;
 }
 print "Now: @data\n";

Cheers!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to