4 # The Scottish Local Government Elections Order 2007
14 # We edit Prefs as we go
25 if ($opt =~ m/^[A-Z]/) {
26 die "unknown option $_ for $what";
27 } elsif ($opt =~ m/^[a-z]/) {
28 print STDERR "warning (line $.): unknown option $_ for $what\n";
35 foreach $_ (split / /, $') {
36 if (m/^_?[Ss]eats=(\d+)/) {
39 unkopt "election", $_;
42 } elsif (m/^(\w+) = (\S*) \|/) {
43 my ($cand,$desc) = @_;
44 unkopt "candidate $cand", $_ foreach split / /, $';
45 $cands{$cand}{Desc} = $desc;
46 } elsif (m/^(\w*) :\s*(.*)\s*\|(.*)/) {
47 my ($voter,$prefs,$opts) = ($1,$2,$3);
48 $v = { Voter => $voter };
49 push @{ $v->{Prefs} }, [ $_ =~ m/\w+/g ]
50 foreach split /\s+/, $prefs;
51 foreach $_ (split / /, $opts) {
52 if (m/^_?[Ww]eight=(\d+)/(\d+)$/) {
53 $v->{Weight} = $1 / $2;
54 } elsif (m/^_?[Ww]eight=([0-9.]+)$/) {
55 $v->{Weight} = new Math::BigRat $1;
57 unkopt "voter $v->{Voter}", $_;
69 # Takes each argument, which should be a ballot, sorts
70 # it into $cand{CAND}{Votes} according to first preference.
71 # Strips that first preference from the ballot.
72 # If the first preference has been eliminated, strips it
73 # and looks for further preferences.
75 my $firstprefs = shift @{ $v->{Prefs} };
76 if (!$firstprefs || !@$firstprefs) {
77 vlog $v, "no more preferences, non transferable";
78 push @non_transferable, $v;
81 if (@$firstprefs > 1) {
82 vlog $v, "splitting due to several equal first preferences";
83 foreach my $fpref (@$firstprefs) {
86 Weight => $v->{Weight} / @$firstprefs,
87 Prefs => [ [ $fpref ], @{ $v->{Prefs} } ],
89 vlog $v, "split for $fpref";
95 my $nprefs = scalar @{ $v->{Prefs}