use strict; use warnings; my %assocs; while (<DATA>) { my ($k, $v) = split; $assocs{$k} = $v; } my %roots; $roots{$_} = 1 for keys %assocs; $roots{$_} = 0 for values %assocs; my @chains; for my $root (grep $roots{$_}, keys %roots) { my $node = $root; my @chain; while (defined($node)) { push @chain, $node; $node = $assocs{$node}; } push @chains, \@chain; } { local $\ = "\n"; local $, = "\t"; print @$_ for @chains; } __DATA__ read book eat apple book novel apple banana play football tennis football novel mazagine
eat apple banana play football read book novel mazagine tennis football
Oops, the output is different than what you asked for. Did I misunderstand the question?
In reply to Re: compare 2 arrays of strings and form a table
by ikegami
in thread compare 2 arrays of strings and form a table
by sharan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |