in reply to Re: Reversing a singly linked list
in thread Reversing a singly linked list

OK Thanks for the response...
But would you be knowing why the following is running into infinite loop ?
what am I doing wrong here
## Reversing linked list $curr=$head; while (defined ($curr->{next})) { $curr->{next} = { data =>$curr->{data}, next => $curr }; $curr = $curr->{next}; } print Dumper $curr;

Replies are listed 'Best First'.
Re^3: Reversing a singly linked list
by LanX (Saint) on Feb 15, 2016 at 16:46 UTC
    Because you always effectively assign next => $curr , hence it's always defined.

    Try Data::Dumper to check if your data is what you think it should be.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!