From: Ian Jackson Date: Mon, 22 Aug 2016 17:10:35 +0000 (+0100) Subject: compute-scottish-stv: --sort=alpha X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=5b395082d4e913cd3049505065af086380c0016c compute-scottish-stv: --sort=alpha --- diff --git a/compute-scottish-stv b/compute-scottish-stv index 4760407..81dc6ad 100755 --- a/compute-scottish-stv +++ b/compute-scottish-stv @@ -58,6 +58,8 @@ $SIG{__DIE__} = sub { die $_[0]; }; +sub total_history_cmp (); + sub unkopt ($$) { my ($what,$opt) = @_; if ($opt =~ m/^[A-Z]/) { @@ -67,6 +69,19 @@ sub unkopt ($$) { } } +my $display_cmp = \&total_history_cmp; + +while (@ARGV && $ARGV[0] =~ m/^\-/) { + $_ = shift @ARGV; + if (m/^--$/) { + last; + } elsif (m/^--sort=alpha$/) { + $display_cmp = sub { $b->{Cand} cmp $a->{Cand} }; + } else { + die; + } +} + for (;;) { $_ = <>; if (m/^\| /) { @@ -198,7 +213,7 @@ sub countballots () { $c->{History}[$stage-1] = $c->{Total}; } - foreach my $c (reverse sort total_history_cmp + foreach my $c (reverse sort $display_cmp grep { !$_->{NonCont} } values %cands) { prf "candidate %-10s: %s votes\n", $c->{Cand}, sv $c->{Total}; }