chatchai_j

Danish super league 2019-2020

Nov 27th, 2020
820
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl -w-
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $INPUTFILE = "matches-2019-2020.txt";
  7.  
  8. my %team = ();
  9. my $line_count = 0;
  10.  
  11. open my $f, '<', "$INPUTFILE" or die "Can't open file '$INPUTFILE' : $!\n";
  12. while (my $line = <$f>) {
  13.     $line_count ++;
  14.     my ($day,$mon,$date,$time,$home_team,$away_team,$home_score,$away_score,$spectator) =
  15.     ($line =~ m|^(\S+)\s+(\d+)/(\d+)\s+(\d+)\.\d+\s+(\S+)\s+-\s+(\S+)\s+(\d+)\s+-\s+(\d+)\s+(\d+)\s*$|);
  16.     # print "$home_team $away_team $home_score $away_score $spectator\n";
  17.     my $home_points = ($home_score > $away_score)?3:
  18.               ($home_score == $away_score)?1:0;
  19.     my $away_points = ($away_score > $home_score)?3:
  20.               ($away_score == $home_score)?1:0;
  21.            
  22.     $team{$home_team}->{'score_goal'} += $home_score;
  23.     $team{$home_team}->{'concede_goal'} += $away_score;
  24.     $team{$home_team}->{'points'} += $home_points;
  25.  
  26.     $team{$away_team}->{'score_goal'} += $away_score;
  27.     $team{$away_team}->{'concede_goal'} += $home_score;
  28.     $team{$away_team}->{'points'} += $away_points;
  29. }
  30. close $f;
  31.  
  32. print "Matches = $line_count\n";
  33.  
  34. ## expected result
  35. # team points score_goal concede_goal
  36.  
  37. for my $name (sort {$team{$b}->{'points'} <=> $team{$a}->{'points'}} keys %team) {
  38.     my $points = $team{$name}->{'points'};
  39.     my $score_goal = $team{$name}->{'score_goal'};
  40.     my $concede_goal = $team{$name}->{'concede_goal'};
  41.     printf "%4s %4d %4d %4d\n", $name, $points, $score_goal, $concede_goal;
  42. }
  43.  
  44. 1;
  45.  
RAW Paste Data