YuckFoo has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Detecting Recursion
by Abigail-II (Bishop) on Nov 26, 2002 at 15:07 UTC | |
by Anonymous Monk on Nov 26, 2002 at 23:38 UTC | |
by Abigail-II (Bishop) on Nov 27, 2002 at 09:41 UTC | |
by Anonymous Monk on Dec 01, 2002 at 22:15 UTC | |
Re: Detecting Recursion
by pg (Canon) on Nov 26, 2002 at 20:41 UTC | |
Re: Detecting Recursion
by Anonymous Monk on Nov 26, 2002 at 21:52 UTC |