in reply to Re^5: Tree depth
in thread Tree depth
#!/bin/perl; use strict; use warnings; use List::Util qw/max/; my %graph; while (<>) { chomp; (@row) = split(/ /,$_); foreach $item (@row) { ($node,$value) = split(/->/,$item,2); $graph{$node} = $value; } sub depth { return max map { $_ and 1 + depth($graph{$_}) } @_; shift @_ } print depth(keys %graph); print "\n"; @row = (); %graph = "" }
Here are the error messages that I get:
Global symbol "@row" requires explicit package name at count_PT.prl li +ne 11. Global symbol "$item" requires explicit package name at count_PT.prl l +ine 12.
still confusing...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Tree depth
by moritz (Cardinal) on Mar 13, 2012 at 15:57 UTC | |
by katarinahm (Initiate) on Mar 14, 2012 at 07:32 UTC |