Hi all,
I'm a perl beginner, and when I tries to practice delete built-in, I find it's
not working as I supposed to.
44 my %employ_list = ("e10220" => "Du", "e10250" => "Vic");
45 # iterate thru with each
46 while ( my ($k, $v) = each %employ_list ) {
47 print " before: key:$k => value:$v \n";
48 if ($k eq "e10220") { delete $employ_list{$k}; }
49 $employ_list{$k} = undef;
50 print "after: key:$k => value:$v \n";
51 }
52 my @elist = %employ_list;
53 print @elist;
OUTPUT:
before: key:e10250 => value:Vic
after: key:e10250 => value:Vic
before: key:e10220 => value:Du
after: key:e10220 => value:Du
Use of uninitialized value $elist[1] in print at ./e6.pl line 53.
Use of uninitialized value $elist[3] in print at ./e6.pl line 53.
e10250e10220
the delete built-in doesn't work, the output of print "after" is still the
original dict. However, when I try to remove the if condition, simply put
delete $employ_list{"e10220"} there, it works.
I can't figure out why, also, the line #49 doesn't work either until I print
the dict outside the while loop, I would expect the print "after" should be
empty.
---
Regards !
Alex Chiang
---
Regards !
Alex Chiang