awohld has asked for the wisdom of the Perl Monks concerning the following question:
There are two data structures that are returned from DBI->fetchall_arrayref
I want to compare the arrays in both structures against each other and match on a specific element in the array, in this case the third element. All the arrays that match I want to store into a new data structure
Here is as far as I got, I need help with the subroutine:
#!/usr/bin/perl -w use strict; use Data::Dumper; # Array Reference my @array1 = ( ["a", "b", "match"], ["c", "d", "e"], ["f", "g", "h"], ["i", "j", "k"], ); my @array2 = ( ["l", "m", "z"], ["n", "o", "p"], ["q", "r", "s"], ["t", "u", "match"], ); # Make data structure similar to DBI's ->fetchall_arrayref; my $array_ref1 = \@array1; my $array_ref2 = \@array2; # Pass in data structures and define # which element to match against. my @matchedLists = &commonLists( \$array_ref1, \$array_ref2, 2 ); print Dumper \@matchedLists; sub commonLists { my ( $array_ref1, $array_ref2, $elementToMatch ) = @_; # Find the common lists where element $elementToMatch matches. # Result should return both lists that have "match" # in their third element. return \@match; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to match specific elements of multiple array_references
by ikegami (Patriarch) on Jun 09, 2006 at 06:27 UTC | |
|
Re: How to match specific elements of multiple array_references
by ambrus (Abbot) on Jun 09, 2006 at 11:36 UTC |