use strict;
use XML::Simple;
my $ref = XMLin('activity.log.xml');
my %what;
my %who;
print("Parsed\n");
foreach my $key1 (keys(%$ref)) {
    foreach my $element (@{$ref->{$key1}}) {
	if (ref($element) eq 'HASH') {
	    my $res = (split(m{(?:/|%2f)},$element->{'resource'}))[-1];
	    $res = &unescape($res);
	    $what{$element->{'student'}}{$res}++;
	    $who{$res}{$element->{'student'}}++;
	}
    }
}

use Data::Dumper;
$Data::Dumper::Sortkeys=1;
print(&Dumper(\%who));

sub unescape {
    my $str=shift;
    $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    return $str;
}
