This is a perfect use case for a dbm like DB_File, DBM::Deep or even SDBM_File (that is the worst of the lot, but comes with Perl). Then you can have a hash that is transparently mirrored in a file, and accessing it will be much more efficient than your solution.

That would look something like this (untested):

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTML::TokeParser; use MIME::Lite; use Fcntl; use SDBM_File; tie my %url_seen, 'SDBM_File', 'urls.dbm', O_RDWR|O_CREAT, 0666); while (1) { my $msg; my @search = ("broken hdtv","fix hdtv","does not work hdtv"); my $connection = WWW::Mechanize->new(); foreach my $term (@search) { $connection->get("http://portland.craigslist.org/"); $connection->form_number(1); $connection->field("query",$term); $connection->click(); my @link = $connection->find_all_links(url_regex => qr/(ele|zip +)\/[0-9]+/i); foreach my $link (@link) { my $tempLink=$link->url_abs; chomp $tempLink; if (not $url_seen{$tempLink}) { $url_seen{$tempLink} = 1; $msg = MIME::Lite->new( To =>'xxxxxxxxxx@vtext.com', Subject =>'CL Link', Type =>'text/plain; charset="iso-8859-1"', Data =>"There is a new link on craigslist." ); close OUTFILE; } } } if ( $msg ) { $msg->send; } sleep(300); }

In reply to Re: Is there a better way to do this? I need to keep track of results... by tilly
in thread Is there a better way to do this? I need to keep track of results... by walkingthecow

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.