ok, what i'm trying to do is, eventually, after everything is done, print the line that the results came from with the results.

first, i think there's an easier way to do this as i'm sorta tieing my brain in knots thinking about what array of what hash is going where. second, if this is the best way to do this, how do i print the string and not the array value (what it seems to be printing) in the final loop?

#!/usr/bin/perl use DBI; my $searcher = "owner.manager, owner.owner, owner.man"; my $dbh = DBI->connect('DBI:mysql:db;host=localhost', 'user', 'pass') 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 ( $uwordi{ $string }[ 0 ] == 1 ) { push @{ $uword{ $string } }, $line; next; } $uword{ $string }[ 0 ] = 1; push @{ $uword{ $string } }, $line; } } $count = 0; while ( $key = keys %uword ) { my ( $imo, $owner, $manown, $manager ); my $sstring = $uword{ $key }; my $select = qq/SELECT $searcher /; my $from = qq/FROM owner, data /; my $where = qq/WHERE MATCH( $searcher ) AGAINST('+ +$sstring' IN BOOLEAN MODE) /; my $join = qq/AND owner.num = data.num/; my $query = $select . $from . $where . $join; print "SQL: $query\n"; my $sth = $dbh->prepare( $query ); $sth->execute; $sth->bind_columns( \$manager, \$owner, \$man ); while ( $sth->fetch ) { if ( defined( $owner ) ) { $data[$count] = $owner; $count++; } if ( defined( $man ) ) { $data[$count] = $manown; $count++; } if ( defined( $manager ) ) { $data[$count] = $manager; $count++ } } foreach my $string ( @data ) { next if !defined ($string); if ( $seen{ $string }[ 0 ] == 1 ) { for my $value (1 .. $#{ $uword{ $string } } ) +{ push @{ $seen{ $string } }, $uword{ $s +tring }[ $value ]; } next; } $seen{ $string }[ 0 ] = 1; for my $value (1 .. $#{ $uword{ $string } } ) { push @{ $seen{ $string } }, $uword{ $string }[ + $value ]; } } } $dbh->disconnect;

In reply to keeping context in a loop by ag4ve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.