The Mudcat Café TM
Thread #144423   Message #3339726
Posted By: Bert
17-Apr-12 - 06:06 PM
Thread Name: Tech: Book Inventory Software
Subject: RE: Tech: Book Inventory Software
If you want a simple database here is one that I use.

It is a simple text file database that uses a single file.

The record separator is a single right brace in the first column like this

}
your first record goes here
}
the next one here
}

The file is free format so you can choose to format your records however you choose. You will need to download and install perl which is free.

Here is the code

#!c:\perl\bin\perl.exe



$Infile="phone.txt";


print "Enter search word(s): ";

chop($pats = );

$pats =~ s/^\s*(.*)$/$1/;

@pats = split(/\s+/, $pats);



while (@pats)
{
print "searching for: ", join(" & ", @pats), "\n";
$/ = "}";


if ($pats eq "s")
{
    print STDERR "\n Wait while saving result to file named lastsearch\n";

    @pats=@oldsearch;
   
open(TEXTFILE,">lastsearch.txt") ||
      die "Can't open lastsearch: $!\n";

   open(I, $Infile) ||
       die "Can't open $Infile: $!\n";

   while($line = )
    {
      $| = 1;

    $num = grep($line =~/$_/i, @pats);

    print TEXTFILE $line if ($num == @pats);
    }
    close I;

   close(TEXTFILE);
    print STDERR " Done saving result\n";

}

else

{
    @oldsearch=@pats;

    open(I, $Infile) ||
      die "Can't open $Infile: $!\n";

   $Dummy = "a";

   while(($line = ) && ($Dummy ne "q"))
    {
      $| = 1;

      $num = grep($line =~/$_/i, @pats);


    if ($num == @pats)
      {   
       print $line ;
       $/ = "\n";
       chop($Dummy=);

       $/ = "}";

      }
    }
}
   close(I);

$/ = "\n";

print "\nEnter search words or \ns to save previous result: ";

chop($pats = );

$pats =~ s/^\s*(.*)$/$1/;

@pats = split(/\s+/, $pats);

}

open(I, "intro");

while($line = )
{
print $line;
}
close(I);