I'm still learning Perl, and my current effort is trying to learn how to manipulate elements within a multidimensional array. Specifically, I'd like to loop over a number of arrays, performing the same operation on all the elements of all the arrays. For a test problem I have 2 arrays:
and I want to make all of the letter "e"'s upper case. (e->E)@days=qw(mon tues wed thurs fri sat sun); @cols=qw(red orange yellow green blue indigo violet);
So, I tried this:
but, obviously it only updates the values in the new array @vars and not the @days or @cols arrays.#! /usr/bin/perl @days=qw(mon tues wed thurs fri sat sun); @cols=qw(red orange yellow green blue indigo violet); @vars=( @days, @cols); s/e/E/g for @vars; foreach (@vars) { print "$_\n"; } print "@days\n"; print "@cols\n";
Then I tried using array references
@vars=( \@days, \@cols);
but that didn't work either (prob 'cause I don't really understand array references, yet).
Is there a simple way to do this?
Thanks
In reply to Regex's and Multidimensional Arrays by Mad_Mac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |