#!/usr/bin/perl
my @testArray = qw(apple apple1 apple2 banana);
my $testElement1 = "apple1";
my $testElement2 = "banana";
my $Counter = 0; my %testHash = {};
%testHash = map { $_ => $Counter++} @testArray;
print "Test element 1 exists!\n" if (exists $testHash{$testElement1});
print "Test element 2 exists!\n" if (exists $testHash{$testElement2});
No comments:
Post a Comment