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.
In reply to Return reference to hash keys by miketosh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |