in reply to Adding Unique Elements to Array
Expanding on RazorbladeBidet's remark:
my @ary = qw ( 0 0 1 1 1 ); my $val = 0; # or whatever push @ary, $val unless exists ${{ map { $_ => undef } @ary }}{$val};
Advantages:
1. Preserves original array order.
2. If duplicate elements already exist in the array, leaves them alone (note that the OP said 'only allow the value onto the array if it is not already included', with no reference to any possible pre-existing duplicates in the array).
Disadvantages:
1. See (2) above.
2. Not, er, readily comprehensible.
dave
|
|---|