[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

perl, loop through an array of strings, substitute character, and save it back to an array

my @fields = ('Larry', 'Curly', 'Moe');

I want loop through the fields, replace all 'r' with 'R', and save it back to the same array @fields.
0
rgbcof
Asked:
rgbcof
2 Solutions
 
ishandoCommented:
one way would be:

foreach $fld (@fields) { $fld =~ s/r/R/ig; }


0
 
ozoCommented:
s/r/R/g for @fields;
0
 
rgbcofAuthor Commented:
Both works.  Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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