in reply to Setting up a hash in a linear search through XML

Fletch has got at the heart of your problem. I'd add three things to his observation. I'm also confused by your XML. Will it ever contain more than one act? If so, how do you know when the act ends (since the ACT node seems to end with the title)? I'm going to assume here that you've got only one act (and one play) per XML file, and suggest something that might work. (My XPath is rusty, so take this with a healthy grain of salt.)
for my $scene ( $doc->findnodes('/PLAY/SCENE') ) { ITEM: for my $item ( $scene->findnodes('SPEECH') ) { my $speaker = $item->findvalue('SPEAKER'); next ITEM unless $speaker eq $searchterm; push @{$act{$scene}}, [ map { $_->to_literal } $item->findno +des('LINE') ]; } }
You could dump this with something like
for my $scene ( keys %act ) { print "SCENE $scene:\n"; print "$searchterm:\n", join "\n", @$_ for @{$act{$scene}}; }

Replies are listed 'Best First'.
Re^2: Setting up a hash in a linear search through XML
by Anonymous Monk on Oct 30, 2008 at 09:45 UTC
    Many thanks for this and to both of you for explaining where I've gone wrong so I can learn from it.
      It should be noted that, despite the errors we've pointed out, you did one thing very much right: You started with use strict; use warnings;. I'd be willing to bet that that played some role in helping you remember the my %act declaration, so already you've seen the usefulness of it.