programming-examples/perl/Hash/The exists function returns true if a hash key (or array index) has been defined, and false if not.pl

10 lines
344 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#Format: exists $ASSOC_ARRAY{KEY}
#!/usr/bin/perl
%employees=("Tester" => "Joe",
"Coder" => "Teddy",
"Clerk" => "Tom",
);
print "exists.\n" if exists $employees{"Tester"};
print "The Clerk exists.\n" if exists $employees{"Clerk"};
print "The Boss does not exist.\n" if not exists $employees{"Boss"};