If you have one graph per line, you should empty %graph before reading a line, or even better, declare it on the inside of the while-loop to limit its scope, and pass it on to the depth subroutine.
By the way, my code isn't optimized for large trees (because your example wasn't very large), it might make sense to cache depths if a graph is much larger.
In reply to Re^3: Tree depth
by moritz
in thread Tree depth
by katarinahm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |