in reply to How do you add class array values
Others have already answered your question, but nobody has mentioned that you don't need to use my @fields; in the third line of your code.
Your new method creates an array ref ($this) which contains a value whose key is fields. This hash element is independent of any other data structure in your code - it isn't connected to the @fields you have already declared.
|
|---|