From d4cf3755e09c69d46236a21f92b50ff380e25482 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Sun, 14 Jun 2026 09:20:57 +0200 Subject: [PATCH] Replace deprecated smartmatch with List::Util::any The smartmatch operator (~~) is deprecated and emits warnings on modern Perl. All uses were scalar-in-list membership tests, now expressed with List::Util::any (or numeric == for the enum case). Fixes #277 Assisted-by: Claude:claude-opus-4-8 --- bin/ledger2beancount | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/ledger2beancount b/bin/ledger2beancount index 2c57b27..119a4ec 100755 --- a/bin/ledger2beancount +++ b/bin/ledger2beancount @@ -11,7 +11,7 @@ use warnings; use strict; -use experimental 'smartmatch'; +use List::Util qw/any/; use utf8; use feature 'unicode_strings'; use open qw/:std :utf8/; @@ -543,7 +543,7 @@ sub create_metadata($$$$) { $metadata->[KEY] = map_metadata $metadata->[KEY]; # Check if we should store as metadata or as links - if (defined $config->{link_tags} && lc $metadata->[KEY] ~~ [ map lc $_, @{$config->{link_tags}} ]) { + if (defined $config->{link_tags} && do { my $key = lc $metadata->[KEY]; any { $_ eq $key } map lc $_, @{$config->{link_tags}} }) { return create_tag $metadata->[DEPTH], [ "^" . map_tag $metadata->[VALUE] ]; } else { $metadata->[TYPE] = META; @@ -1264,7 +1264,7 @@ sub map_metadata($) { # Certain tags won't show up in the beancount file, so there's no need # to warn about them. - if (!($key ~~ [$config->{narration_tag}, $config->{payee_tag}, $config->{payer_tag}])) { + if (!(any { defined $_ && $_ eq $key } $config->{narration_tag}, $config->{payee_tag}, $config->{payer_tag})) { $ledger_metadata{$ledger_key} = 1; } @@ -1326,7 +1326,7 @@ sub map_account($) { print_warning_once("Account $account not allowed; it needs a sub-account, e.g. $account:Subaccount"); $account .= ":Subaccount"; } - if (!($root ~~ @beancount_root_names)) { + if (!(any { $_ eq $root } @beancount_root_names)) { my $root_type = get_root_type $root; if ($root_type) { print_warning_once("Non-standard root name $root used; setting beancount option name_$root_type"); @@ -1440,7 +1440,7 @@ sub print_warning($) { sub print_warning_once($) { my ($warning) = @_; - push @conversion_notes, $warning if !($warning ~~ @conversion_notes); + push @conversion_notes, $warning if !(any { $_ eq $warning } @conversion_notes); } @@ -1886,7 +1886,7 @@ sub set_txn_payee($@) { } } # Return metadata but skip all metadata where the key is in @skip_tags. - @metadata = grep { $_->[TYPE] != META || !($_->[KEY] ~~ @skip_tags)} @metadata; + @metadata = grep { my $m = $_; $m->[TYPE] != META || !(any { $_ eq $m->[KEY] } @skip_tags)} @metadata; return $header, @metadata; } @@ -1929,7 +1929,7 @@ sub process_txn($$@) { $header->[TAG] = \@tags if @tags; my @header_data = grep { $_->[TYPE] == META } @{$metadata}; - push @header_data, (grep { $_->[TYPE] ~~ [ META, TAG ] } reverse @ledger_apply); + push @header_data, (grep { $_->[TYPE] == META || $_->[TYPE] == TAG } reverse @ledger_apply); if (defined $+{auxdate} && defined $config->{auxdate_tag}) { push @header_data, create_metadata 1, $config->{auxdate_tag}, pp_date($+{auxdate}, $year), 1; } @@ -2108,8 +2108,8 @@ sub process_txn($$@) { # prices). my $commodity1 = $i->[AMOUNT]->[CURRENCY]; my $commodity2 = $i->[PRICE]->[AMOUNT]->[CURRENCY]; - if (defined $i->[PRICE]->[AMOUNT]->[FIXATED] || $commodity1 ~~ @{$config->{currency_is_commodity}} || - ((length $commodity1 != 3 || length $commodity2 != 3) && !($commodity1 ~~ @{$config->{commodity_is_currency}} || $commodity2 ~~ @{$config->{commodity_is_currency}}))) { + if (defined $i->[PRICE]->[AMOUNT]->[FIXATED] || (any { $_ eq $commodity1 } @{$config->{currency_is_commodity}}) || + ((length $commodity1 != 3 || length $commodity2 != 3) && !((any { $_ eq $commodity1 } @{$config->{commodity_is_currency}}) || (any { $_ eq $commodity2 } @{$config->{commodity_is_currency}})))) { $i->[COST] = $i->[PRICE]; $i->[PRICE] = undef; } @@ -2697,29 +2697,29 @@ while (@input) { # Check for renames foreach (sort keys %ledger_accounts) { my $map = map_account $_; - if ($_ ne $map && !($map ~~ [values %{$config->{account_map}}]) && - !($map ~~ [values %account_regex_map])) { + if ($_ ne $map && !(any { $_ eq $map } values %{$config->{account_map}}) && + !(any { $_ eq $map } values %account_regex_map)) { print_warning "Account $_ renamed to $map"; } } foreach (sort keys %ledger_commodities) { my $map = map_commodity $_; - if ($_ ne $map && $_ ne qq("$map") && !($map ~~ [values %{$config->{commodity_map}}])) { + if ($_ ne $map && $_ ne qq("$map") && !(any { $_ eq $map } values %{$config->{commodity_map}})) { print_warning "Commodity $_ renamed to $map"; } } foreach (sort keys %ledger_tags) { my $map = map_tag $_; - if ($_ ne $map && !($map ~~ [values %{$config->{tag_map}}])) { + if ($_ ne $map && !(any { $_ eq $map } values %{$config->{tag_map}})) { print_warning "Tag $_ renamed to $map"; } } foreach (sort keys %ledger_metadata) { my $map = map_metadata $_; - if ($_ ne $map && !($map ~~ [values %{$config->{metadata_map}}])) { + if ($_ ne $map && !(any { $_ eq $map } values %{$config->{metadata_map}})) { print_warning "Metadata key $_ renamed to $map"; } } @@ -2786,7 +2786,7 @@ if (scalar keys %root_names) { # development if we add a wrong entry to %root_mappings. foreach my $root (keys %root_mappings) { my $type = $root_mappings{$root}; - if (!(ucfirst $type ~~ @beancount_root_names)) { + if (do { my $t = ucfirst $type; !(any { $_ eq $t } @beancount_root_names) }) { die "Invalid %root_mappings entry for $root: invalid type $type"; } }