Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flatfile db issue

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
I've been working on this for a few days now and I cannot get the code to work fully. There are 2 questionable parts..

1) Use of uninitialized value in pattern match: refering to $ARGV[0] line.

2) The database doesn't store the last word it flips through. Ever.

The script loads the dictionary just fine and prints it to screen without a problem (also checks GoDaddy properly, too). It doesn't, however, ever load the last word into the database.

My guess:
1) Since this script loads a large dictionary file, it never fully executes (is why I need the db to work). I exit this command-line with CTRL+C which I thought may be the problem with the database not saving.

I just tried capturing the SIG and exiting normally in hopes it'd close properly and leave the database in tact, but it doesn't. The database has no data. The data is there, the $word always has data, but it never stores after the script closes with CTRL+C.

Can ANYONE come up with an idea what the problem might be? Or how I can go around fixing it?

Code:
#!/usr/bin/perl

use warnings;
use strict;

use DB_File;
use POSIX;

my $dbase = "dbase.db";
my %dbase;

my $dict  = "dictionary.txt";
my $saved = "saved.txt";

#foreach (keys %dbase)
#{  print "$_ => $dbase{$_}\n ."; }
#exit;

$SIG{INT} = \&handler;

my $search = "[URL unfurl="true"]https://www.godaddy.com/gdshop/default.asp";[/URL]

open(DICT, $dict) or die "Cannot open $dict because $!";
my $words = <DICT>;
my @words = split(/ /, $words);

close(DICT) or die "Cannot close $dict because $!";

if ($ARGV[0] =~ m/con/i)
{
   my $start = $dbase{"word"};
   shift @words until $words[0] =~ m/$start/;
   print "con found!\n";
}

my $count = -1;


open(SAVED, ">>$saved") or die "Cannot open $saved because $!";


foreach my $word (@words)
{
  tie (%dbase, 'DB_File', $dbase, O_CREAT|O_RDWR, 0644)
     || die "Died tying database\nReason: $!\n";

  $count++;

  print "Searching $word..\n";
  use [URL unfurl="true"]WWW::Mechanize;[/URL]
  my $mech = [URL unfurl="true"]WWW::Mechanize->new();[/URL]
  $mech->get($search);

  $mech->submit_form(
       form_name      => "LookupForm",
       fields         => {
       domainToCheck  => "$word"
       }
   );
  
  $dbase{"word"} = "$word";

  my $results = $mech->content;

  if ($results =~ m/This domain name IS AVAILABLE/i)
  {
     print SAVED "$word.com\n";
     print "\t $word AVAILABLE!\n\a";

  }
  else
  {
     print "\t $word TAKEN\n";
  }
  
  untie %dbase;
}

close(SAVED) or die "Cannot close $saved because $!";

sub handler
{
   print "Program has been stopped.\n";
   exit(0);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top