Hello all, I'm new to perlmonks.org and I have a question regarding MS Access. I have a program that extracts e-mail addresses from web pages and stores them in an Access database as well as a file. When the program ends, the file contains about 7 times more addresses than Access. How do I correct this? Here is the code snippet that I have so far:
use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; sub extractEmail { my($hitPage) = @_; my $email; my $emailPresent = 0; my $webTitle = HTML::TokeParser->new($hitPage); my $titlePage = ""; my $Conn = Win32::OLE->new("ADODB.Connection"); my $RecSet = Win32::OLE->new("ADODB.Recordset"); my $DBTable = "Addresses"; my $DBFile = "g:\\PO system\\emailaddresses.mdb"; my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb +)};DBQ=$DBFile"; #Opens the connection to the database $Conn->Open($DSN); $RecSet->Open($DBTable, $Conn,adLockOptimistic, adOpenDynamic); + #The current page is searched for any <MAILTO:> tags and extracts +email addresses and stores them in a database and file while($$hitPage =~ /mailto:.*?\.(com|ca|net)/g) { $email = $&; $email =~ s/mailto://g; $titlePage = $webTitle->get_trimmed_text("/title"); print OUTFILE $email, "\t\t", $webTitle->get_trimmed_text("/title" +); $RecSet->AddNew(["Email Address", "Website Title"], [$email, $titl +ePage]); $emailPresent = 1; } $RecSet->Close(); $Conn->Close(); return $emailPresent; }
This whole code is inside a loop. I don't think the constant opening and closing of the database is the problem (although it slows the program down), but I could be wrong. Thanks for any help!

In reply to Adding data to an access database by Raziel

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.