It is a little bit complex and confusing at first when you see a reference in perl because it looks familiar and unfamiliar at the same time:
$self->{_tagStack} = [];
That looks like a bit of OOP style programming because of the $self reference.
You maybe dug that out of something similar to this:
-
sub new {
-
my $self = {};
-
$self->{NAME} = undef;
-
$self->{AGE} = undef;
-
$self->{PEERS} = [];
-
bless($self); # but see below
-
return $self;
-
}
-
first is this line:
it creates a reference to an anonymous hash. Thats what the curly {} brackets signify. This is often refered to as the "hash-reference-as-an-object" idiom.
Then the next three lines define some hash keys and some initial values:
- $self->{NAME} = undef;
-
$self->{AGE} = undef;
-
$self->{PEERS} = [];
the last one is a hash key that has an anonymous array (an empty array) as its value. We can assume some data will be stuck into that array later. Its essentially the same as this example:
- $array->{PEERS} = ['foo', 'bar', 'baz'];
$array is a reference to a hash of array, to get to the data stored in a reference you have to use dereferencing:
- print $array->{PEERS}[0]; (prints foo)
Thats what the arrow operator "->" is used for. What you want is to read about complex data structures with perl and maybe object oriented programming.
http://perldoc.perl.org/perldsc.html