From ae09d3e1fefd0ef4d15365c23e7bcb82a904a25e Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Sat, 13 Jun 2020 19:33:52 +0200 Subject: Use @h{@a} = () instead of undef @h{@a} as it works even when @a is empty. --- challenge-009/e-choroba/perl5/ch-1.pl | 2 +- challenge-057/e-choroba/perl/Tree.pm | 2 +- challenge-060/e-choroba/perl/ch-2.pl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 challenge-009/e-choroba/perl5/ch-1.pl diff --git a/challenge-009/e-choroba/perl5/ch-1.pl b/challenge-009/e-choroba/perl5/ch-1.pl old mode 100644 new mode 100755 index 4a74e71fe3..561873482a --- a/challenge-009/e-choroba/perl5/ch-1.pl +++ b/challenge-009/e-choroba/perl5/ch-1.pl @@ -6,7 +6,7 @@ use feature qw{ say }; sub distinct_digits { my ($n) = @_; my %d; - undef @d{split //, $n}; + @d{split //, $n} = (); return keys %d } diff --git a/challenge-057/e-choroba/perl/Tree.pm b/challenge-057/e-choroba/perl/Tree.pm index a0a4a8a51f..176c5f574a 100644 --- a/challenge-057/e-choroba/perl/Tree.pm +++ b/challenge-057/e-choroba/perl/Tree.pm @@ -28,7 +28,7 @@ sub from_edges { push @children, $child; } my %root; - undef @root{ keys %tree }; + @root{ keys %tree } = (); delete @root{ @children }; my @roots = keys %root; die "One root not found: @roots." if @roots != 1; diff --git a/challenge-060/e-choroba/perl/ch-2.pl b/challenge-060/e-choroba/perl/ch-2.pl index 0894531600..438c4e5954 100755 --- a/challenge-060/e-choroba/perl/ch-2.pl +++ b/challenge-060/e-choroba/perl/ch-2.pl @@ -5,7 +5,7 @@ use strict; sub extend { my ($length, $short, $long) = @_; my %next; - undef @next{@$short}; + @next{@$short} = (); for my $i (0 .. $#$short) { for my $j (0 .. $#$short) { my $new = 0 + ($short->[$i] . $short->[$j]); @@ -25,7 +25,7 @@ sub extend { sub find { my ($length, $greater, @list) = @_; my @long = grep $length == length $_, @list; - my %long; undef @long{@long} if @long; + my %long; @long{@long} = (); return grep $greater > $_, extend($length, \@list, \%long); } -- cgit