20/01/24 23:55:14 qxZ+oily.net
>>671 Perl5 (goto 関数を使っていますが、perl5ではこれはcontinuationです)
use feature qw{current_sub signatures};
no warnings 'experimental::signatures';
@sx = (A => B, A => D, B => E, D => E);
sub {
if (@_) {
($a, $b) = (shift, shift);
push @lx, $a unless $h{$a};
push @{$h{$a}}, $b;
$r{$b}{$a} = 1;
goto __SUB__;
}
}->(@sx);
@ax = grep{! $r{$_}} @lx;
sub ($a, $d) {
print "$d$a\n";
__SUB__->($b, "_$d") while $b = shift @{$h{$a}};
}->($_, '') for @ax;
実行結果
$ perl 16_671.pl
A
_B
__E
_D
__E