Rather than special-casing -a, loop through any arguments (and
complain if there is anything other than -a).
Use .=
Use unless rather than if (!) ...
Signed-off-by: Matthew Vernon <matthewv@chiark.greenend.org.uk>
}
sub action_list {
- my ($q, $listall);
- if ($priv) { $listall = 1; }
- if (@ARGV) {
- my $v = shift @ARGV;
- if ($v ne "-a") {
- die "only legal argument to list is -a";
- } else { $listall=1; }
+ my $listall = 0;
+ $listall ||= $priv;
+ while (@ARGV) {
+ last unless $ARGV[0] =~ m/^-/;
+ $_ = shift @ARGV;
+ last if m/^--?$/;
+ if (m/^-a$/) {
+ $listall=1;
+ } else {
+ die "unknown option to list \`$_'\n";
+ }
}
nomoreargs;
- $q="SELECT * FROM addrs WHERE user=?";
- if (!$listall) {
- $q = $q. " AND NOT redirect = ''";
- }
- $q = $q. " ORDER BY localpart";
+ my $q = "SELECT * FROM addrs WHERE user=?";
+ $q .= " AND NOT redirect = ''" unless $listall;
+ $q .= " ORDER BY localpart";
$q = $dbh->prepare($q);
$q->execute($user);
listq($q);