in reply to Re: Can't use an undefined value as a HASH reference
in thread Can't use an undefined value as a HASH reference

while (my $line = <>) { chomp $line; my $tree = build_subtree($line); print Dumper $tree->{children}[0]; print Dumper $tree; walk_postorder($tree,[\&mark_heads,\&annotate]); @{$tree->{children}}[0]->{label} =~ s/^\*//; # undo top-level merge print build_subtree_oneline($tree,1), $/; }

I did have to use both prints. They gave output below.

$VAR1 = undef; $VAR1 = { 'children' => [] };

Not sure where to go from here. But would the $line input be the cause of the problem? The build_subtree($line) subroutine uses it as input.

Also, the correct link to the original script is here: https://github.com/mjpost/dptsg/blob/master/scripts/annotate_spinal_grammar.pl

Replies are listed 'Best First'.
Re^3: Can't use an undefined value as a HASH reference
by stevieb (Canon) on Aug 25, 2015 at 16:08 UTC

    Ok, so now take a step back, and tell us what data you are sending into your script, ie. how you are calling it and with what arguments (post a example snip from the input file).

    We need to know what is in $line. I can't get to the link with the rest of the code, so I'm unsure how build_subtree compiles its data, and what it expects to find. Do you have another link, or can you post the full code?

      Thank you'll very much for the pointers. It helped me trace through the problem. It's now resolved. I see build_tree was expecting a string that began with parenthesis, like so: "(TOP (S (NP (NP (NNP Pierre) (NNP Vinken))".

      The build_subtree subroutine has a sanity test line as follows

      if ($line !~ /^\(.*\)\s*$/) { print "here: $line\n"; return undef; }

      And input $line has "1 , 4885".