aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2020-06-13 19:33:52 +0200
committerE. Choroba <choroba@matfyz.cz>2020-06-13 19:33:52 +0200
commitae09d3e1fefd0ef4d15365c23e7bcb82a904a25e (patch)
treedbefbf2b246fef5703058b4b10f4cca7d8ad593e
parent8215d517e4db95675998b281ba81ce5c49cc5e8f (diff)
downloadperlweeklychallenge-club-ae09d3e1fefd0ef4d15365c23e7bcb82a904a25e.tar.gz
perlweeklychallenge-club-ae09d3e1fefd0ef4d15365c23e7bcb82a904a25e.tar.bz2
perlweeklychallenge-club-ae09d3e1fefd0ef4d15365c23e7bcb82a904a25e.zip
Use @h{@a} = () instead of undef @h{@a}
as it works even when @a is empty.
-rwxr-xr-x[-rw-r--r--]challenge-009/e-choroba/perl5/ch-1.pl2
-rw-r--r--challenge-057/e-choroba/perl/Tree.pm2
-rwxr-xr-xchallenge-060/e-choroba/perl/ch-2.pl4
3 files changed, 4 insertions, 4 deletions
diff --git a/challenge-009/e-choroba/perl5/ch-1.pl b/challenge-009/e-choroba/perl5/ch-1.pl
index 4a74e71fe3..561873482a 100644..100755
--- 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);
}