The easiest approach would be to review your course material for hints about how to do so.
The second easiest approach is to do this manually for the given example and then encode each step that you do manually into a program.
Maybe the following observations help you analyze the steps to find the length of a linked list:
In reply to Re: Nodes count in Linked List
by Corion
in thread Perl linked list
by Perl_is_Perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |