in reply to $#{$array_ref} changes in loop
Maybe there is a reason for this, but this looks like you should use a different data structure. If I understand it right your AoA looks somewhat like this:
where neither the riderid nor actionid is unique. And you want to find all scores for each rider assuming the riders are in order. If you can assume that much you might be better off with a datastructure like this:$eventscores = [ [riderid, actionid, score], [riderid, actionid, score], [riderid, actionid, score], ... ];
in which case your code would become$eventscores = { riderid => { actionid => score actionid => score ... }, ... };
I don't know what are you doing with the @scores later, but in either case I do think you should consider starting to use a database. If eg. you wanted to get an average score for each rider you could just run a query like thisforeach my $rider (keys %$eventscores) { my @scores = values %{$eventscores->{$rider}}; # or, if you need the scores in order my @scores = map {$eventscores->{$rider}{$_}} sort keys %{$eventscore +s->{$rider}}; # do something with $rider and @scores }
and be done with it. If you do not want to have to install a server just use DBD::SQLite.select riderid, AVG(score) from eventscores group by riderid order by riderid
If you don't know SQL yet, learn it. It'll make many things much easier.
|
|---|