in reply to Deleting hash entry
Output:use strict; use warnings; use Data::Dumper; my $hash = { 'abc' => { def => 1, ghi => 2, jkl => 3, }, 'mno' => { pqr => 4, stu => 3, vwx => 5, }, 2 => { def => 5, stu => 2, }, 0 => { def => 3, stu => 1, }, }; print Dumper $hash; for my $key (keys %$hash) { delete $$hash{$key} if $key =~ /^\d+$/ } print Dumper $hash;
$ perl delete_hash.pl $VAR1 = { 'mno' => { 'pqr' => 4, 'vwx' => 5, 'stu' => 3 }, '0' => { 'def' => 3, 'stu' => 1 }, 'abc' => { 'def' => 1, 'jkl' => 3, 'ghi' => 2 }, '2' => { 'def' => 5, 'stu' => 2 } }; $VAR1 = { 'mno' => { 'pqr' => 4, 'vwx' => 5, 'stu' => 3 }, 'abc' => { 'def' => 1, 'jkl' => 3, 'ghi' => 2 } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Deleting hash entry
by Marshall (Canon) on May 13, 2017 at 00:28 UTC | |
by Laurent_R (Canon) on May 13, 2017 at 15:34 UTC |