in reply to Regex's and Multidimensional Arrays

When you use the assignment @vars=( @days, @cols);, you flatten both arrays into a single list, which gets copied to @vars, as you have observed. The assignment @vars=( \@days, \@cols);, on the other hand, creates an array of array references, with the power to modify the original arrays as desired so long as you take the extra depth into account. You can visualize this data with the core module Data::Dumper (See How can I visualize my complex data structure?). The basic way to accomplish this would be to simply use nested foreach loops:

for my $array_ref (@vars) { s/e/E/g for @$array_ref; } foreach (map @$_, @vars) { print "$_\n"; }

For details on using references, give perlreftut a read.

Replies are listed 'Best First'.
Re^2: Regex's and Multidimensional Arrays
by dasgar (Priest) on Sep 15, 2010 at 15:42 UTC

    I think that kennethk nailed the diagnosis. Of course, the question now is, are you really wanting an array of references to arrays? If not, perhaps you can describe what you're trying to do and someone can point you in the right direction. I could be wrong, but I suspect that you really didn't want array of references to arrays.

    If you're wanting to learn more about multidimensional arrays, you might want to checkout perllol, which is on 'List of Lists' or also known as multidimensional arrays.

      Also take a look at the Data Structures Cookbook perldsc.