in reply to Re^2: Blessing object changes array attribute in array of arrays?
in thread Blessing object changes array attribute into array of arrays?

You seem to be unaware of scoping. The best article I know about scoping is Coping With Scoping, which explains you all the stuff to know about global variables and lexical variables.

For the problem at hand, yes, declaring @log_lines via my is exactly what you need, because then, each reference taken to @log_lines will be unique and point to its own incarnation of @log_lines, which seems to be what you want as $self->{log_lines} seems to be intended to be an instance variable and not a class/package variable.

You also seem to have a misconception about how objects work in Perl, stemming from how you (don't) interpret scope. Variables declared via my are lexical variables that are only visible (under their name) within the closest set of enclosing curly braces ({}). An object usually is a (blessed) reference to a hash and you have to stuff all instance variables into that hash. The declaration in the constructor is not really related to that.

  • Comment on Re^3: Blessing object changes array attribute in array of arrays?