From d013df91b9313dcfdae17d39bfdc53fe930b2ca1 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 3 Dec 2022 07:10:22 +0100 Subject: [PATCH] Day 3: use $_ everywhere --- 2022/05.pl | 8 ++++---- 2022/06.pl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/2022/05.pl b/2022/05.pl index a7e1f9d..5002bf9 100755 --- a/2022/05.pl +++ b/2022/05.pl @@ -8,9 +8,9 @@ my $sum; while (<>) { chomp; substr($_, length()/2, 0) = ' '; - my ($c) = /(.)\S*\s\S*\1/; - $sum += $c =~ /[A-Z]/ - ? ord($c) - ord('A') + 27 - : ord($c) - ord('a') + 1; + s/\A\S*(.)\S*\s\S*\1\S*\z/$1/; + $sum += /[A-Z]/ + ? ord() - ord('A') + 27 + : ord() - ord('a') + 1; } say $sum; diff --git a/2022/06.pl b/2022/06.pl index 84ea0fb..39b07ae 100755 --- a/2022/06.pl +++ b/2022/06.pl @@ -11,9 +11,9 @@ while (<>) { next if $. % 3; $_ = $s; $s = ''; - my ($c) = /(.)\S*\s\S*\1\S*\s\S*\1/; - $sum += $c =~ /[A-Z]/ - ? ord($c) - ord('A') + 27 - : ord($c) - ord('a') + 1; + s/\A\S*(.)\S*\s\S*\1\S*\s\S*\1\S*\s?\z/$1/; + $sum += /[A-Z]/ + ? ord() - ord('A') + 27 + : ord() - ord('a') + 1; } say $sum; -- 2.43.5