Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex's and Multidimensional Arrays
by kennethk (Abbot) on Sep 15, 2010 at 15:28 UTC | |
by dasgar (Priest) on Sep 15, 2010 at 15:42 UTC | |
by AnomalousMonk (Archbishop) on Sep 15, 2010 at 17:23 UTC | |
|
Re: Regex's and Multidimensional Arrays
by toolic (Bishop) on Sep 15, 2010 at 15:24 UTC | |
|
Re: Regex's and Multidimensional Arrays
by suhailck (Friar) on Sep 15, 2010 at 18:16 UTC | |
|
Re: Regex's and Multidimensional Arrays
by planetscape (Chancellor) on Sep 15, 2010 at 19:58 UTC | |
|
Re: Regex's and Multidimensional Arrays
by umasuresh (Hermit) on Sep 15, 2010 at 15:26 UTC | |
|
Re: Regex's and Multidimensional Arrays
by gnosti (Chaplain) on Sep 16, 2010 at 05:11 UTC | |
|
Re: Regex's and Multidimensional Arrays
by changma_ha (Sexton) on Sep 16, 2010 at 04:46 UTC |