Linked List

  1. #!/usr/bin/perl
  2.  
  3. $list = undef;
  4. foreach (reverse 1..5) {
  5.     $list = [ $list, $_ * $_ ];
  6. }
  7.  
  8. use constant NEXT => 0;
  9. use constant VAL  => 1;
  10.  
  11. $four    = $list->[NEXT];
  12. $nine    = $four->[NEXT];
  13. $sixteen = $nine->[NEXT];
  14.  
  15. $nine->[NEXT]    = $sixteen->[NEXT];
  16. $sixteen->[NEXT] = $nine;
  17. $four->[NEXT]    = $sixteen;

  1. #!/usr/bin/perl
  2.  
  3. $list = $tail = undef;
  4.  
  5. foreach (1..5) {
  6.     my $node = [ undef, $_ * $_ ];
  7.     $list = undef;
  8.     $tail = \$list;
  9.     foreach (1..5) {
  10.     my $node = [ undef, $_ * $_ ];
  11.     $$tail = $node;
  12.     $tail = \$node->[NEXT];
  13.     }
  14. }