#!/usr/bin/perl use strict; use warnings; my $head = {data => 0, prev => undef, next => undef}; my $previous = $head; open FILE, "){ chomp; $previous->{next} = { "data" => $_ , "next" => undef, "prev" => $previous, }; $previous = $previous->{next}; } ### Inserting element at the beginning of the list after the head node my $curr = $head; $curr->{next}= { "data" => 30, "next" => $curr->{next}, "prev" => $curr, }; ### Inserting element at the end of the list before the tail node $curr = $previous; $curr->{prev}= { "data" => 40, "next" => $curr, "prev" => $curr->{prev}, }; ## Printing from head print "printing from head \n"; $curr = $head; while (1) { last unless defined $curr->{next}; print "Current: ", $curr->{data}, "\tPrevious: ", $curr->{prev}{data} // "", "\tNext: ", $curr->{next}{data} // "", "\n"; $curr = $curr->{next}; } ## printing from tail print "Printing From tail \n"; while (1) { last unless defined $curr->{prev}; print "Current: ", $curr->{data}, "\tPrevious: ", $curr->{prev}{data} // "", "\tNext: ", $curr->{next}{data} // "", "\n"; $curr = $curr->{prev}; }