Topological Sort

Score: 380.46 (pass)

#!perl
sub visit{my$z=$_[0];return if@{$l{$z}}[0]eq 2;exit 1if@{$l{$z}}[0]eq 1;@{$l{$z}}[0]=1;$c=0;foreach(@{$l{$z}}){visit($_)if$c ne 0;$c++}@{$l{$z}}[0]=2;unshift(@o,$z);}while(<>){($f,$s)=split;push@{$l{$f}},0if!@{$l{$f}};push@{$l{$s}},0if!@{$l{$s}};if($f ne$s){$g=0;$c=0;for (@{$l{$f}}){$g=1if($c ne 0)&&($_ eq$s);$c++}push @{$l{$f}}, $s if!$g;}}visit($_)for keys%l;print "$_
"for@o;

Score: 380.46 (pass)

#!perl
sub visit{my$z=$_[0];return if@{$l{$z}}[0]eq 2;exit 1if@{$l{$z}}[0]eq 1;@{$l{$z}}[0]=1;$c=0;foreach(@{$l{$z}}){visit($_)if$c ne 0;$c++}@{$l{$z}}[0]=2;unshift(@o,$z);}while(<>){($f,$s)=split;push@{$l{$f}},0if!@{$l{$f}};push@{$l{$s}},0if!@{$l{$s}};if($f ne$s){$g=0;$c=0;for (@{$l{$f}}){$g=1if($c ne 0)&&($_ eq$s);$c++}push @{$l{$f}}, $s if!$g;}}visit($_)for keys%l;print "$_
"for@o;

Score: 517.48 (fail)

I'm a beginner in both perl and perl golf, but enjoyed this exercise anyway. Thanks!

#!perl
my @l, @o;sub visit{if (@{$l{$_[0]}}[0] != 0){return;}@{$l{$_[0]}}[0]=1;$count=0;foreach $v (@{$l{$_[0]}}){if ($count ne 0){if ($v eq $_[1]){exit 1;}visit($v, $_[1]);}$count++;}@{$l{$_[0]}}[0]=2;unshift(@o, $_[0]);return;}while (<>) {($f, $s) = split;if (!@{$l{$f}}){push @{$l{$f}}, 0;   }if (!@{$l{$s}}){push @{$l{$s}}, 0;   }if ($f ne $s){$found = 0;foreach $item (@{$l{$f}}){if ($item eq $s){$found = 1;}}if (!$found){push @{$l{$f}}, $s;   }}}foreach $key (keys %l){visit($key, $key);}foreach $i (@o){print "$i
";}

Score: 551.48 (pass)

#!perl
my @l, @o;sub visit{if (@{$l{$_[0]}}[0] eq 2){return;}if (@{$l{$_[0]}}[0] eq 1){exit 1;}@{$l{$_[0]}}[0]=1;$count=0;foreach $v (@{$l{$_[0]}}){if ($count ne 0){visit($v);}$count++;}@{$l{$_[0]}}[0]=2;unshift(@o, $_[0]);return;}while (<>) {($f, $s) = split;if (!@{$l{$f}}){push @{$l{$f}}, 0;   }if (!@{$l{$s}}){push @{$l{$s}}, 0;   }if ($f ne $s){$found = 0;$count =0;foreach $item (@{$l{$f}}){if (($count ne 0) && ($item eq $s)){$found = 1;}$count++;}if (!$found){push @{$l{$f}}, $s;   }}}foreach $key (keys %l){visit($key);}foreach $i (@o){print "$i
";}

Score: 555.49 (fail)

Here we go again

#!perl
my @l, @o;sub visit{if (@{$l{$_[0]}}[0] != 0){return;}@{$l{$_[0]}}[0]=1;$count=0;foreach $v (@{$l{$_[0]}}){if ($count ne 0){if ($v eq $_[1]){exit 1;}visit($v, $_[1]);}$count++;}@{$l{$_[0]}}[0]=2;unshift(@o, $_[0]);return;}while (<>) {($f, $s) = split;if (!@{$l{$f}}){push @{$l{$f}}, 0;   }if (!@{$l{$s}}){push @{$l{$s}}, 0;   }if ($f ne $s){$found = 0;$count =0;foreach $item (@{$l{$f}}){if (($count ne 0) && ($item eq $s)){$found = 1;}$count++;}if (!$found){push @{$l{$f}}, $s;   }}}foreach $key (keys %l){visit($key, $key);}foreach $i (@o){print "$i
";}