
set5think
Novice
Oct 12, 2008, 11:15 PM
Post #1 of 5
(740 views)
|
XPath, XMLParser, and an anonymous array troubles
|
Can't Post
|
|
Okay, I am at a total loss, and am considering breaking something, so please someone help me. I am trying to use an anonymous array of arrays, send that reference off to a subroutine which then dereferences the variable, and then I'm trying to use two separate counters to make this xml parse dynamic. Let's start with my arrays:
my @offensive_stats = qw(offensive-plays-yards offensive-plays-number offensive-plays-average-yards-per); my @passing_stats = qw(passes-yards-net passes-yards-gross times-thrown-total passes-yards-lost passes-attempts passes-completions passes-interceptions passes-average-yards-per); There are a couple more arrays with several entries, but for the purpose of the example, two should be enough. Then here's my anonymous array of arrays:
my $offensive = [ [@offensive_stats], [@passing_stats], [@rushing_stats], [@downprogress_stats], ]; Here's this other anonymous array that contains some strings to build my path in the xml file(this will make more sense when we get to the subroutine):
my $path_ref= ['offensive','passing','rushing','down-progress']; Here's my call to my subroutine so you see I'm passing it through properly:
&get_team_stats(\@$offensive, \@$path_ref); And finally, here is the subroutine:
sub get_team_stats { my $ref1 = $_[0]; my $ref2 = $_[1]; my $counter1 = 0; while ($while) { $alt_counter = 0; while ($while) { my $attribute = @{$ref1}->[$counter1][$alt_counter]; #print "$base_path/team[1]/team-stats/team-stats-american-football/stats-american-football-".@{$ref2}->[$counter1].'/@'.$attribute."\n"; $team_info_hash{$attribute} = &get_data("$base_path/team[1]/team-stats/team-stats-american-football/stats-american-football-".@{$ref2}->[$counter1].'/@'.$attribute); #print "this is a ref $attribute $team_info_hash{$attribute} ocounter: $counter1 altcounter: $alt_counter\n"; last if (&get_data("$base_path/team[1]/team-stats/team-stats-american-football/stats-american-football-".@{$ref2}->[$counter1].'/@'.$attribute) eq ''); $alt_counter++; } last if ($counter1 == 4); $counter1++; } } the reason my "last if" condition is checking to end it if the counter = 4 is just for debugging purposes. Anyway, the problem lies in that it's not working on the condition that if the &get_data subroutine doesn't find anything at the path it's at, then stop the loop, and perform the increment and move on to the next path if there is one. The results are that I have an invalid query. I'll attach my code in here as well as a test xml file. You won't need to type the name of the file as a command line argument, since I've made the script dependent on this particular xml file for your convenience. Thank you in advance to you brave souls.
(This post was edited by set5think on Oct 13, 2008, 2:00 AM)
|