use strict; use warnings; use DBI; my @theseWords; my @theseLines; my @found; my %Count; my %Line; my %theseWords; my ( $line, $word, $count, $LineNum ); my $file = "c:\\webroot\\dickens\\46.txt"; open ( IN, $file ) || die "$file not found\n"; @theseLines = ; close (IN); chomp @theseLines; foreach $line ( @theseLines ) { $count++; $line = lc $line; $line =~ s/[.,:;?!]//g; while ( $line =~ /\b\w+\b/g ) { $word = $&; if ( $word =~ /\s/ || $word eq "" ) { next } $Count{$word}++; if ( defined $Line{$word} ) { $Line{$word} =~ m/(\d*?)$/; if ( $1 == $count ) { next; } else { $Line{$word} .= ", $count"; } } else { $Line{$word} = $count; } } } my $db = DBI->connect('dbi:mysql:lit:localhost', 'user', 'pw'); my $statement = qq( INSERT INTO dickens VALUES ($word, $Line{$word}) ); my $sth = $db->prepare($statement); @theseWords = keys %Line; @theseWords = sort @theseWords; foreach $word ( @theseWords ) { print ("$word: $Line{$word}\n\n"); $sth->execute(); } $sth->finish; $db->disconnect();