in reply to merging two arrays with OR operation
use bitwise OR ( | ) or logical OR ( || ) on each element. It doesn't have to be a long program, if you use map or other such perl idioms
# [id://1230926] use warnings; use strict; my @array1 = (0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1); my @array2 = (0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1); my @arrayResult = map { $array1[$_] | $array2[$_] } 0 .. $#array1; print "arrayResult = (@arrayResult)\n"; use Test::More tests => 1; is_deeply( \@arrayResult , [0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1] )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: merging two arrays with OR operation
by Anonymous Monk on Mar 05, 2019 at 21:16 UTC | |
by GrandFather (Saint) on Mar 06, 2019 at 20:18 UTC | |
|
Re^2: merging two arrays with OR operation
by stevieb (Canon) on Mar 06, 2019 at 01:20 UTC | |
by pryrt (Abbot) on Mar 06, 2019 at 03:02 UTC |