marknm has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use diagnostics; my $historyFile = 'gsHistToMassSto'; my $doneFlag = findTargetAttribute('last','WorkFlowStatus','status',$h +istoryFile); print "My DONE flag = $doneFlag\n"; eval {my $result = findTargetAttribute('first','WorkFlow','status',$hi +storyFile); print "My result is $result\n";}; sub findTargetAttribute{ use XML::Parser; my ($location,$targetElement,$targetAttribute,$file) = @_; my $parser = XML::Parser->new(Handlers => {Start => \&handle_start}) +; my @results; print "$location, $targetElement, $targetAttribute, $file\n"; $parser->parsefile($file); if($location eq 'first'){return $results[0]} if($location eq 'last'){return $results[-1]} else {return @results} sub handle_start { my($expat, $element, %attrs) = @_; if($element eq $targetElement){ print "Target = $targetElement\n"; if(%attrs){ while(my($key, $value) = each(%attrs)){ if($key eq $targetAttribute){push @results,$value;} } } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: nested subroutines
by Elian (Parson) on Jun 19, 2003 at 19:19 UTC | |
|
Re: nested subroutines
by Zaxo (Archbishop) on Jun 19, 2003 at 20:31 UTC | |
|
Re: nested subroutines
by marknm (Acolyte) on Jun 19, 2003 at 19:55 UTC | |
by Nkuvu (Priest) on Jun 19, 2003 at 20:00 UTC | |
|
Re: nested subroutines
by Nkuvu (Priest) on Jun 19, 2003 at 19:22 UTC |