From 9e1ba7159f64ebfdfe0d6dd444005f045bec07fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Wed, 13 Mar 2024 17:15:31 +0100 Subject: [PATCH] Simplify code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ortega Froysa --- pacundo.pl | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pacundo.pl b/pacundo.pl index bf4663d..02e8dfb 100755 --- a/pacundo.pl +++ b/pacundo.pl @@ -59,7 +59,7 @@ sub read_txs($num_txs = 1) { my $found_txs = 0; my $in_tx = 0; my @undo_txs; - my $pacman_log = File::ReadBackwards->new("/var/log/pacman.log") || + my $pacman_log = File::ReadBackwards->new("/var/log/pacman.log") or die("Failed to load pacman log file.\n$!"); while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) { @@ -122,23 +122,16 @@ $n, $tx->{action}, $tx->{pkg_name} my @sel = split(' ', ); - foreach my $i (@sel) { - if ($i =~ /^[0-9]+-[0-9]+$/) { - my ($start, $end) = $i =~ /^([0-9]+)-([0-9]+)$/; - if ($start >= $end) { - die("Invalid range: $start-$end\n"); - } - push(@sel, ($start..$end)); - } + foreach my $i (grep({/^[0-9]+-[0-9]+$/} @sel)) { + my ($start, $end) = $i =~ /^([0-9]+)-([0-9]+)$/; + die("Invalid range: $start-$end\n") if ($start >= $end); + push(@sel, ($start..$end)); } @sel = sort grep({!/[0-9+]-[0-9+]/} @sel); my @sel_undo; - - foreach my $i (@sel) { - push(@sel_undo, $undo_txs[$i-1]); - } + push(@sel_undo, $undo_txs[$_-1]) foreach (@sel); return @sel_undo; }