in reply to Re: problems dereferencing an array of arrays as a hash value
in thread problems dereferencing an array of arrays as a hash value

Thanks! That did it, but I'm not quite clear why. Can you explain a little what's going on there?
  • Comment on Re^2: problems dereferencing an array of arrays as a hash value

Replies are listed 'Best First'.
Re^3: problems dereferencing an array of arrays as a hash value
by gmargo (Hermit) on Nov 23, 2009 at 17:42 UTC

    The brackets [] create a reference to an anonymous array. With an array inside the brackets like [ @pktClassList ], the contents of the @pktClassList array are copied into the new anonymous array.

    There is a different way to get the same effect, but which avoids the second copy. If the @pktClassList array is a local variable in a subroutine, which gets used only once before going out of scope, then you could have used the @pktClassList array directly like this:

    case /packetclassifierlist/ { $tlvHash{pktClassList} = \@pktClassLi +st }

    The key is the scope of the original @pktClassList array - when the variable goes out of scope, it becomes an anonymous array by virtue of being referenced by the %tlvHash hash. Quite unlike the C language.

    See perlref for more info on references. Anonymous arrays are addressed early in the document.