Gossamer Forum
Home : General : Perl Programming :

I need to create a simple record counter for DBman

Quote Reply
I need to create a simple record counter for DBman
I hope one of you Perl gurus can help me out here, or at least point me in the right direction. I'm not a Perl programmer, but I can move it about, if u know what I mean:) This could be really useful for DBman people though.
I've searched through the usual places to no avail.
Anyway. Here goes.

I need a simple script that performs two tasks.

1. displays the total number of records in say, default.db, on a web page.

2. Compares the total number of records of default.db against say olddefault.db and displays the difference on a webpage.

So, if;

Default.db contains;
cat
dog
mouse

olddefault.db contains;
cat
dog

I need.
Pets for sale today: 3
Pets sold yesterday: 1

Hugs and kisses to anyone who helps:)
Thank you

Dezire




Quote Reply
Re: I need to create a simple record counter for DBman In reply to
This should go in the DBMAN Customization forum but hey...

Code:
open(COUNT, "</path/to/default.count") || die "Can't open DBMAN count file : $!";
$total=<COUNT>;
close(COUNT);
To find the difference in numbers for two databases, use the code above but change the paths to the different count files for each database and name the second variable $total2. Then do:

Code:
$difference = $total - $total2;

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Code:
my $curr = 1;
my $old = 1;
open (CURR, "default.db") or die $!;
$curr++ while (<CURR>);
close CURR;
open (OLD, "olddefault.db") or die $!;
$old++ while (<OLD>);
close OLD;
my $sold = $curr - $old;
Of course you should really do some field checking instead of relying on the number of records.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: I need to create a simple record counter for DBman In reply to
The dynamic duo Paul and Junko to the rescue again!

Thanks. This looks great, however, I just a little more help. Keeping in mind that this is a seperate script outside DBman.
How would I call the script and display say $difference on a static web page?

Dezire

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Hi,

You can use SSI:

Code:
<!--#exec cgi="script.cgi"-->
Inside the script just add:

Code:
print $difference;
(and remember the path to perl and print the header etc).

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Wow ! worked first time !

Thanks again for all your help.

Dezire

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
You're welcome.

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Ooops ! well.... err.. after a number of silly errors and loss of hard drive, I lost the working script generated from this thread.
This is my reconstruction but it doesn't insert anything where the SSI is placed. Can someone see any obvious errors with this;

#!/usr/local/bin/perl
# =====================================================================
# ---------------------
# Record Counter V1.0
# ---------------------
#
# =====================================================================

my $curr = 1;
open (CURR, "default.db") or die $!;
$curr++ while (<CURR>);
close CURR;
print $curr;
exit;
}


Thank you :(

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Try what I said Smile - no need to go to all that effort when default.count holds the total:

Code:
#!/usr/local/bin/perl
# ---------------------
# Record Counter V1.0
# ---------------------
my $num;
Code:
open (CURR, "/FULL/PATH/TO/default.count") || &error($!);
$num=<CURR>;
close(CURR);
Code:
print $num;
Code:
sub error {
Code:
my ($msg) = shift;
print $msg;
exit;
Code:
}
Installations:http://www.wiredon.net/gt/

Quote Reply
Re: I need to create a simple record counter for DBman In reply to
Thanks Paul.
I'm still getting the same result. SSI call being replaced with nothing.
At least I know the SSI sees the script though.
Does it work for you?