I have a hash of hashes among which one of the sub-hashes is an array. It looks something like this:
my %pop = ( 0 => {status => "0", interactions => [], statuscount => "0"}, 1 => {status => "0", interactions => [], statuscount => "0"},
I also have a random number generation sequence which populates the interactions array with a list of numbers that represent other people that person "0" or "1" has made contact with. I have a statement that prevents the random number sequence from picking the person itself, i.e. (1,1), the reverse interaction (assuming that (1,0) and (0,1) are the same interaction), and the same person twice. I am having problems with the code that prevents the same person twice.
$pair = int(rand($pop)); redo if $test{$element.'-'.$pair} or $test{$pair.'-'.$element} or +$pair==$element; redo if $pair == (exists @{$pop{$element}{interactions}});
Am I writing it wrong? I have also tried using "grep{$_ eq $pair}" in place of "exists" and neither quite work. "exists" returns the error below and the "grep" works but doesn't prevent repeats in the list.  exists argument is not a HASH or ARRAY element or a subroutine at disease_outbreak_array.pl line 84. Any help appreciated.

In reply to searching for elements by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.