miketosh has asked for the wisdom of the Perl Monks concerning the following question:
I have two array refs, and I'd like back an array ref of the unique values in the two. My problem is I can't seem to figure out how to return a reference to keys %hash from my function.
Here is what I have:sub unique { my @refs = @_; my %files = (); foreach my $ref (@refs) { $files{$_}++ foreach (@$ref); } my @arr = keys %files; return \@arr; }
I'd like to simplify the last two lines so that I don't need to declare a new array. (I'm using Perl 5.005_03) Any other suggestions for improvement are welcome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Return reference to hash keys
by kennethk (Abbot) on Nov 30, 2010 at 14:13 UTC | |
by miketosh (Acolyte) on Nov 30, 2010 at 20:24 UTC | |
by kennethk (Abbot) on Nov 30, 2010 at 21:14 UTC | |
|
Re: Return reference to hash keys
by Limbic~Region (Chancellor) on Nov 30, 2010 at 14:14 UTC | |
|
OT Re: Return reference to hash keys
by ww (Archbishop) on Nov 30, 2010 at 14:15 UTC | |
by miketosh (Acolyte) on Nov 30, 2010 at 20:30 UTC |