puterboy has asked for the wisdom of the Perl Monks concerning the following question:
I need to merge the elements of several arrays without repeats. Currently, I am using hash slices as follows:
my %temphash; @temphash{@array1, @array2} = (); my @mergedkeys = keys %temphash
I would love to eliminate the temporary hash by using anonymous hashes. But I seem to be missing the right magical combination of braces, ampersands, and percent signs to make it work. For example, I tried to no avail various things like:
my @mergedkeys = keys %{{@array1, @array2}}Similarly, is there any way to eliminate the temporary hash when I want to delete any elements of array2 appearing in array1 (along with eliminating any duplicates)? Currently, I am using the following code with a temporary hash:
my %temphash; @temphash{@array1} = (); delete @temphash{@array1}; my @newarray = keys %temphash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Merge arrays - seeking slicker approach
by kennethk (Abbot) on Dec 21, 2010 at 15:00 UTC | |
|
Re: Merge arrays - seeking slicker approach
by roboticus (Chancellor) on Dec 21, 2010 at 15:12 UTC | |
|
Re: Merge arrays - seeking slicker approach
by eff_i_g (Curate) on Dec 21, 2010 at 15:01 UTC | |
|
Re: Merge arrays - seeking slicker approach
by ikegami (Patriarch) on Dec 21, 2010 at 18:19 UTC | |
|
Re: Merge arrays - seeking slicker approach
by Marshall (Canon) on Dec 21, 2010 at 18:36 UTC | |
|
Re: Merge arrays - seeking slicker approach
by ikegami (Patriarch) on Dec 21, 2010 at 18:20 UTC | |
|
Re: Merge arrays - seeking slicker approach
by JavaFan (Canon) on Dec 21, 2010 at 17:41 UTC |