• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

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');
0
blnukem
Asked:
blnukem
  • 2
1 Solution
 
ps15Commented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now