#!/usr/bin/perl -w use strict; my $home = "Axoville Spd"; print "city,age,wood,clay,iron,crop\n"; my %scoutings = (); open(SCOUTINGS,"./reports.pl --filter-type=scout --filter-src=\"Axoville Spd\" | ./reportresources.pl |"); while() { my @v = split(/,/,$_); my @old = $scoutings{$v[3]}; if ((not defined $old[0]) || ($old[0] > $v[5])) { $scoutings{ $v[3] } = [$v[7],$v[8],$v[9],$v[10],$v[11]]; } } close(SCOUTINGS); warn "investigating attacks...\n"; open(ATTACKS,"./reports.pl --filter-type=attack --filter-src=\"Axoville Spd\" | ./reportresources.pl |"); while() { my @v = split(/,/,$_); my $arr = @$scoutings{$v[3]}; if (defined $arr) { if (@$arr[0] > $v[7]) # If attack happened after scouting { print "$v[3]\n"; @$arr[1] -= $v[8]; @$arr[2] -= $v[9]; @$arr[3] -= $v[10]; @$arr[4] -= $v[11]; } } } close(ATTACKS); warn "Outputting text\n"; for my $key(keys %scoutings) { my $arr = $scoutings{$key}; print "$key,".join(",",@$arr)."\n"; }