From 86e3814fb2481edef05b3b8221125ad31fe7bde6 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 18 Apr 2026 11:36:12 +0200 Subject: [PATCH] loop dropdb + support multiple selection --- scripts/dropdb.pl | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/dropdb.pl b/scripts/dropdb.pl index 578e1ef..1571d0f 100755 --- a/scripts/dropdb.pl +++ b/scripts/dropdb.pl @@ -46,17 +46,23 @@ my $dbh = DBI->connect( "DBI:MariaDB:host=$db_host;port=$db_port", or die 'Failed to connect to database: ' . $DBI::errstr; say 'Connected to database'; -say 'Existing databases:'; -my @db_names = - sort - map { s/DBI:MariaDB://r } - grep { !/information_schema|smchurla_ll/ } $dbh->data_sources(); -foreach (@db_names) { say " - $_"; } +while (1) { + say 'Existing databases:'; + my @db_names = + sort + map { s/DBI:MariaDB://r } + grep { !/information_schema|smchurla_ll/ } $dbh->data_sources(); + foreach (@db_names) { say " - $_"; } -print 'Enter name to delete: '; -my $db_sel = ; -chomp $db_sel; -$dbh->do("drop database `$db_sel`") - or die "Failed to drop database: " . $dbh->errstr; + print 'Enter single name or comma-separated list to delete: '; + my $db_sel = ; + chomp $db_sel; + my @selected_dbs = $db_sel eq "all" ? @db_names : split( ',', $db_sel ); + foreach (@selected_dbs) { + $dbh->do("drop database `$_`") + or die "Failed to drop database: " . $dbh->errstr; + + } +} $dbh->disconnect or warn $dbh->errstr;