in reply to Re^5: Tree depth
in thread Tree depth

This is how my code looks like when I'm using strict and warnings:
#!/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

      Now it works!! Thank you for your patience!