monks of wisdom,
i am writing this script which takes unique elements out of a text and stores them in an array. These values are then compared to an existing arrayref(a word repository:single_words) whose values come from the database. The point is to enter the values of unique elements of the array found in arrayref in a frequency table in the database. for the values not found in the arrayref the enteries have to be made both in the repository table (single_words) and the frequency table (single_frequency). everything works perfecly in my code till the point i am comparing the values and entering them in single_words. But it starts to screw up when i come to the values not found in the arrayref. Also, the else loop doesnt work at all the way it is written here, if i include it with the comparision if then it works but there are a lot repitions of values. I know that i am doing some mistake with my loops, can anybody correct me? also is there a better way to do it ??
my $dbh = DBI->connect("dbi:mysql:concordance","sid" , $password);
my @row = $dbh->selectcol_arrayref("select doc from doc");
@single_uniq = grep { ! $seen{$_} ++ } @single;
my @row = $dbh->selectall_arrayref("select word,word_id from single_wo
+rds");
my $row1 = $dbh->selectall_arrayref("select max(word_id) from single_w
+ords");
$count = ($row1->[0][0]);
$x = ($row1->[0][0]);
$nfound = 0;
single:for ($j=0;$j<=$#single_uniq;$j++){
$frequency = ($seen{$single_uniq[$j]});
word:for ($i= 0; $i<= $count ; $i++){
if ("$single_uniq[$j]" eq "$row[0][$i][0]"){
$found = 1;
if ($found){
$dbh->do ("insert into single_frequency values('$row
+[0][$i][0]',$frequency,'$row[0][$i][1]')");
}
else
{
$nfound = ($nfound + 1);
if ($nfound = 0){
$dbh->do ("insert into single_words values('','$single_un
+iq[$j]',1)");
my $max1 = $dbh->selectall_arrayref("select max(word_id) f
+rom single_words");
$dbh->do ("insert into single_frequency values('$single_un
+iq[$j]',$frequency,'$max1->[0][0]')");
$x = ($x + 1);
}
}
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.