package doublyLinkedList; sub new { my ($class, @elements) = @_; my $self = bless { start => undef, }, $class; $self->push(@elements); return $self; } sub push { my ($self, @elements) = @_; for my $element (@elements) { my $newNode = { element => $element, next => undef, prev => undef, }; # newNode becomes an anonymous hash ref. if(not defined $self->{start}) { $self->{start} = $newNode; # the list is empty, assign to start as is } else { $newNode->{next} = $self->{start}; $self->{start}{prev} = $newNode; $self->{start} = $newNode; # else make the new node point to start and then assign new node as the new start of the list. } } return; }