Thanks Uri and Jepp, 

that was exactly the information I was looking for.

----- Original Message -----
From: "Uri Guttman" <u...@stemsystems.com>
To: "Jeff Pang" <jeff_p...@sina.com>
Cc: beginners@perl.org
Sent: Sunday, October 31, 2010 6:39:50 PM GMT +01:00 Amsterdam / Berlin / Bern 
/ Rome / Stockholm / Vienna
Subject: Re: anonymous hash reference

>>>>> "JP" == Jeff Pang <jeff_p...@sina.com> writes:

  JP> print check_for_exists('name','foo');

  JP> sub check_for_exists {
  JP>    my $key = shift;
  JP>    my $value = shift;

  JP>     for my $item (@$foo) {
  JP>         if ($item->{$key} eq $value ) {
  JP>            return 1;
  JP>         }
  JP>     }

  JP>     return 0;
  JP> }

that reduces to just:

        $item->{'foo'} eq $value ;

there is no reason for a full sub for that. and it has a flaw (as does
the OP's question). which comparison op do you use? hash values can be
numbers too so eq may not work as expected on them.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to