implement a node list in Perl
implementation, list, perl
Solution
You should be storing `$self` everywhere instead of `\$class`. Storing $class is simply storing the name of the class, not the object itself.
Also, for `$self->{nextNode}` I'd store an `undef` instead of a blank string. Or better yet, simply don't create it at all and use `exists` when checking if it is there.
Problem
I wrote the following module but am not sure how to refer to the "last" and "head" nodes. As well as storing the address of the next node in "{nextNode}" in the previous node. I am trying to save the reference of the class when storing it but later it's complaining: "Not a HASH reference at List.pm"; which I understand why but am not sure how the syntax would be. If I de-reference $head and $last ($$last->{nextNode} = \$class) then I think it's using the actual name of my class; List and not the previous object like I want to. ``` package List; my $head = undef; my $last = undef; sub new { my $class = shift; # init the head of the list if ($head == undef) { $head = \$class; print "updated head to:$head", "\n"; } $last = \$class; $last->{nextNode} = \$class; # update previous node to point on this new one print "updated last to:$last", "\n"; my $self = {}; $self->{value} = shift; $self->{nextNode} = ""; # reset next to nothing since this node is last return bless $self, $class; } ``` Thanks guys