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.my %pop = ( 0 => {status => "0", interactions => [], statuscount => "0"}, 1 => {status => "0", interactions => [], statuscount => "0"},
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.$pair = int(rand($pop)); redo if $test{$element.'-'.$pair} or $test{$pair.'-'.$element} or +$pair==$element; redo if $pair == (exists @{$pop{$element}{interactions}});
In reply to searching for elements by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |