Hello again,
I still have some questions concerning the linked list.
The problem now is, that I try to access the head-pointer of the list after I 
left the loop in which the list were made. 

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

use constant NEXT => 0;
use constant VAL  => 1;


our $kopf = undef;
my $zeiger = \$kopf;
my $zahl = 5;

foreach ( 1..$zahl )
{
 my $node = [ undef, $_ * $_ ];

 if ( ! $kopf )
 {
  $zeiger = \$node;
  $kopf = \$node;
 }

 else
 {
  $$zeiger -> [ NEXT ] = \$node;
  $zeiger = $node -> [ NEXT ];
 }

 #print $node -> [ VAL ], "\n";
}

print Dumper ( $kopf );
print $$kopf -> [ VAL ], "\n";
$zeiger = $kopf;

while ( ref $zeiger  )
{
 print $$zeiger -> [ VAL ], "\n";
 $zeiger = $$zeiger -> [ NEXT ];
}

But the output shows me just the first two nodes: 1 and 4.
And if I create the nodes inside the loop as global ( our ) then it puts me 
only the last node out.
What did I wrong?

Gruss Christian


-- 
Christian Stalp

Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI)
Obere Zahlbacher Straße 69
55131 Mainz
Tel.: 06131/ 17-6852

E-Mail: [EMAIL PROTECTED]
Internet: www.imbei.de

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to