use strict; my $list = undef; my $lastnode = \$list; while (1) { print 'nput, utput : '; chomp (my $input = ); if ($input eq 'i') { ($list, $lastnode) = add ($list, $lastnode); next; } if ($input eq 'o') { show ($list); next; } } sub add { my ($list, $lastnode) = @_; chomp (my $input = ); my $newnode = [undef, $input]; $$lastnode = $newnode; $lastnode = \$newnode -> [0]; return ($list, $lastnode); } sub show { my $list = shift; for (my $node = $list; $node; $node = $node -> [0]) { print $node -> [1] . "\n"; } } #### $$lastnode = $newnode; #### use strict; my $list = undef; my $lastnode = \$list; while (1) { print 'nput, utput : '; chomp (my $input = ); if ($input eq 'i') { &add; next; } if ($input eq 'o') { &show; next; } } sub add { chomp (my $input = ); my $newnode = [undef, $input]; $$lastnode = $newnode; $lastnode = \$newnode -> [0]; } sub show { for (my $node = $list; $node; $node = $node -> [0]) { print $node -> [1] . "\n"; } }