YuckYuckFoo
#!/usr/bin/perl use strict; my %donts; my %calls; while (chomp (my $line = <DATA>)) { my ($mom, $kid) = split(' ', $line); # First time moms if (!defined($calls{$mom})) { $calls{$mom} = {}; } $calls{$mom}->{$kid}++; print "$mom calls $kid\n"; # First time kids if (!defined($donts{$kid})) { $donts{$kid} = {}; # Kids shouldn't call themselves $donts{$kid}->{$kid}++; print "$kid better not call $kid\n"; } # Kids shouldn't call their mom $donts{$kid}->{$mom}++; # Kids shouldn't call their mom's moms for my $nono (keys(%{$donts{$mom}})) { $donts{$kid}->{$nono}++; print "$kid better not call $nono\n"; # See if they do if ($calls{$kid}->{$nono}) { print "uh-oh\n"; exit; } } } print "whew!\n"; __DATA__ aaa bbb bbb ccc bbb ddd ccc ddd ddd aaa ddd eee
In reply to Detecting Recursion by YuckFoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |