in reply to Why am I getting Can't use string (<string value>) as an ARRAY ref wile "strict refs" in use

I am not sure what you are trying to do. Strictly speaking, perl does not have such a thing as a "multidimensional array". It simulates it very well with an "array of arrays" (or more accurately, an array of array references). You are storing a string in the $ii element of the array @mtab. In the next statement, you use the syntax for "array of arrays". Perl expects that $ii element to contain a reference to one of several arrays (with $jj as the index into that array). The message is telling you that the main array contains the string you stored there rather than a reference. I cannot give you the correct syntax without knowing what you are trying to do. I suspect that a hash would be a better data structure.
Bill
  • Comment on Re: Why am I getting Can't use string (<string value>) as an ARRAY ref wile "strict refs" in use

Replies are listed 'Best First'.
Re^2: Why am I getting Can't use string (<string value>) as an ARRAY ref wile "strict refs" in use
by tobyink (Canon) on Feb 28, 2019 at 16:57 UTC

    There's also multidimensional hashes:

    perl -E'my %x; $x{1,2,3} = 4; print $x{1,2,3}, "\n";'

    They're kinda weirdly implemented and not really used much.

      There's also multidimensional hashes [...] They're kinda weirdly implemented and not really used much.

      Basically, all list elements are joined by $; (defaults to \034 = \x1C = ASCII FS) before using them as hash key. This is not multidimensional, it is just a poor emulation used mainly for awk compatibility.

      Problems:

      • The list elements must not contain the value of $; or else your data becomes garbage.
      • Of course, you should not modify $; at runtime or else your data becomes garbage again.
      • keys and each return the joined keys, not lists of key parts. There is no automatic split.
      • The syntax does not work for slices.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      I found a description of this at Multi dimensional array emulation. It looks like it is creating a hash key from the list, "1,2,3". This seems like it could be a good way to implement a sparse array.

      use warnings; use strict; use Data::Dumper; my %x; $x{1,2,3} = 4; print $x{1,2,3}, "\n"; print Dumper(\%x); __DATA__ 4 $VAR1 = { '1‡˜2‡˜3' => 4 };