Hi,
I have the following code, and I know it is HORRIBLE.
I wonder if I can do it in more efficient and elegant way?
Thanks so much and
Regards, Edward WIJAYA SINGAPORE
__BEGIN__ use strict; use warnings; use Getopt::Std; use Data::Dumper;
my %hash = ( A => 'blabla', B => 'dadada', C => 'tititi', );
my $s = 'A'; my $get = check_ifHash_key_exist(\%hash, $s); print "Got it: $get\n";
#--- this is how I do it (don't laugh) --------------
sub check_ifHash_key_exist {
my ($hash, $str) = @_; my $found_str; my @array = keys %{$hash}; for (my $i= 0; $i < keys %{$hash}; $i++) { if ($array[$i] eq $str) { $found_str = $array[$i]; last; } } return $found_str; } __END__
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>