On Jan 3, Jeff 'japhy' Pinyan said:

>On Jan 3, Nisim, Amit said:
>
>>I need to compare between two Associative Arrays
>>How can I do it ?
>
>In what way(s) do you want to compare them?  To see if they have the same
>keys?  Same keys and values?

For comparing keys and values of two hashes:

  # assume the hashes are the same
  $same = 1;

  # see if the number of keys is the same
  if (keys(%this) != keys(%that)) {
    $same = 0;
  }
  # compare each key-value pair
  else {
    for (keys %this) {
      $same = 0, last unless
        exists $that{$_} and
        $this{$_} eq $that{$_};
    }
  }

After that code, $same will hold either 0 or 1.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to