i am having an issue here, i think the bulk of it revolves around this; print join(',', @uword{ $seen{ $key }[ 1 ] }[ 1 .. $#{ @uword{ $seen( $key ) } } ] );
however, given how that looks, i'm thinking i've got others. so, pretty much, what i do is go through each line and take out the words and take out the duplicate words. i take the hash of those words and put the full text from the lines they came from and push it onto the array reference to that hashref. i then go and search a database for each word and take out the duplicates of the results (keeping the search terms with the results - though there's a minor logic issue with this i think - if two searches bring up the same text, i'll just know about the first). the result string and the word that was searched to find the string are stored to the same type of array reference to a hashref. that all works fine (exept my many to many problem i noted above). my issue is how to print out a slice of an arrayref of a hashref? my underlying problem (i think) is that there has got to be a better way? i've got half a mind to create a temp table in the db to do this, but that doesn't seem like my 'better way' either. thanks #!/usr/bin/perl ##### WHAT # # What names return per search ########## use strict; use warnings; use DBI; my $searcher = "owner.manager, owner.owner, owner.manown"; my $dbh = DBI->connect('DBI:mysql:db;host=localhost', 'user', 'word') or die "Database connection: $!"; open( FILE, "< $ARGV[0]" ); my %uword = (); my %seen = (); my $count = 0; my @data; my $key; my $i = 0; while ( <FILE> ) { my $line = $_; chomp ($line); my @word = split / /, $line; $count = 0; while ( $word[ $count ] ) { $word[ $count ] =~ tr/^[\-a-zA-Z]//; $word[ $count ] =~ s/\'/\\\'/g; $count++; } foreach my $string ( @word ) { if ( $uword{ $string }[ 0 ] == 1 ) { push @{ $uword{ $string } }, $line; next; } $uword{ $string }[ 0 ] = 1; push @{ $uword{ $string } }, $line; } } for my $key ( keys %uword ) { my ( $number, $owner, $manown, $manager ); my $select = qq/SELECT $searcher /; my $from = qq/FROM owner, spd /; my $where = qq/WHERE MATCH( $searcher ) AGAINST('+$key' IN BOOLEAN MODE) /; my $join = qq/AND owner.num = spd.num/; my $query = $select . $from . $where . $join; print "SQL: $query\n"; my $sth = $dbh->prepare( $query ); $sth->execute; $sth->bind_columns( \$manager, \$owner, \$manown ); while ( $sth->fetch ) { if ( defined( $owner ) ) { $data[$count] = $owner; $count++; } if ( defined( $manown ) ) { $data[$count] = $manown; $count++; } if ( defined( $manager ) ) { $data[$count] = $manager; $count++ } } # @data holds full names of data. foreach my $string ( @data ) { # dedupe data and sanity check. next if !defined ($string); # should never be true. next if $seen{ $string }[ 0 ] == 1; # check %seen hash / array for dupe $seen{ $string }[ 0 ] = 1; # define hash of array and assign check to it. $seen{ $string }[ 1 ] = $key; # add word from line to hash for reference. } } $dbh->disconnect; # $key - (below) is the deduped sql string # $seen { $key }[ 1 ] - is the word searched in sql # $uword { '$seen{ $key }[ 1 ]' } - should be the line(s) of test the search string came from for my $key ( keys %seen ) { print "$seen{ $key }[ 1 ], $key,"; print join(',', @uword{ $seen{ $key }[ 1 ] }[ 1 .. $#{ @uword{ $seen( $key ) } } ] ); print "\n"; }