Change The Value Of A Item In An Array


While looping threw an array how do I change the value of a item?

my $NewNameToAdd = "Distance=584";
my $WordToRemove = "Distance::Required=584";

my @Array ('LeftSegmentHeight=45','Distance::Required=584','RightSegmentHeight=789');

DESIRED NEW ARRAY:
my @Array ('LeftSegmentHeight=45','Distance=584','RightSegmentHeight=789');
blnukemAsked:
Who is Participating?
 
ps15Connect With a Mentor Commented:
do something like

foreach(@Array) {
# modify $_ in here
# like s/something/something else/;
s/::.*?=/=/;
}

or

@Array = map {s/::.*?=/=/;$_;} @Array;
0
 
ps15Commented:
for (@Array) {
 if ($_ eq 'Something') {
  $_ = 'something_else';
 }
}
0
 
ozoCommented:
s/::.*?=/=/ for @Array;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.