mdunnbass has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone,
Ideally, I want @group1 to contain all the elements from groups 1 and 2. Or, if for instance group2 also had a D and an E, it would contain everything but the duplicates. But, after running the above code, @group1 remains unchanged. Any glaring errors that pop out at you?
Yet another question from me.. I am trying to combine non-duplicate elements of 2 arrays into 1. I have read the "difference/intersection/union of 2 arrays" FAQ, and I've read the bit by vroom here, but I felt the need to be difficult. *grins*
Here's the bit I've got going so far:
my @group1 = ('A','B','C','D','E'); my @group2 = ('F','G','H','I','J'); foreach my $hit (@group2) { push (@group1, $hit) unless grep { $hit } @group1; }
Ideally, I want @group1 to contain all the elements from groups 1 and 2. Or, if for instance group2 also had a D and an E, it would contain everything but the duplicates. But, after running the above code, @group1 remains unchanged. Any glaring errors that pop out at you?
Something tells me I got this bit of code a few weeks ago here, but looking back through all of my recent questions, I must be missing it somewhere. So, sorry if this is redundant.
Thanks
Matt
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Combining arrays with grep/unless?
by kyle (Abbot) on Feb 09, 2007 at 21:05 UTC | |
Re: Combining arrays with grep/unless?
by Fletch (Bishop) on Feb 09, 2007 at 20:52 UTC | |
Re: Combining arrays with grep/unless?
by ikegami (Patriarch) on Feb 09, 2007 at 20:52 UTC | |
by polettix (Vicar) on Feb 10, 2007 at 00:13 UTC | |
by ikegami (Patriarch) on Feb 10, 2007 at 00:30 UTC | |
by polettix (Vicar) on Feb 10, 2007 at 01:06 UTC | |
by ikegami (Patriarch) on Feb 10, 2007 at 07:18 UTC | |
| |
Re: Combining arrays with grep/unless?
by dragonchild (Archbishop) on Feb 09, 2007 at 21:17 UTC | |
Re: Combining arrays with grep/unless?
by davidrw (Prior) on Feb 10, 2007 at 04:42 UTC | |
Re: Combining arrays with grep/unless?
by dorko (Prior) on Feb 09, 2007 at 23:24 UTC | |
Re: Combining arrays with grep/unless?
by polettix (Vicar) on Feb 10, 2007 at 00:16 UTC |
Back to
Seekers of Perl Wisdom