
terry1738
Novice
Mar 13, 2009, 12:38 AM
Post #18 of 24
(2746 views)
|
Hi Here is the rough up (warts and all) of the main program that I am using to call these 50 sub routines , you asked me for. At the moment I am only calling one subroutine in an attempt to get it to work and because of the problem I am facing trying to use a variable instead of a bare word in a "use" statement. I will not be using 50 elsif statements as that would defeat the purpose of the design in that the clients data maintains the plan he is on. So all I need to do with this program is get the client details from the data base and call the correct subroutine. That seems to be possible using eval "require $xxxx"; My problem is when I do use apc; it works but when do (without changing anything else) require apc; it fails with Undefined subroutine &main::plancontroler called at ./adsldtb.pl line 89, <PHNUM> line 1. So it seems they are not directly interchangeable Thats my only issue now. If anyone can tell me why that is happening I think I can solve all the other issues. Regards Terry #!/usr/bin/perl -w use Date::Manip; use DBI; use DBD::mysql; #use apc; require apc; #$apc="apc"; #eval "require $apc"; my ($outdata, $extracost, $totalcost, $extrac, $wcost, $acost, $profit, $plancost); # format: dbi:db type:db name:host:port my $dsn = 'dbi:mysql:TAC:localhost:3306'; # set the user and password my $user = 'root'; my $pass = 'xxxx'; # now connect and get a database handle my $dbh = DBI->connect($dsn, $user, $pass) or die "Can’t connect to the DB: $DBI::errstr\n"; #first get all the phone numbers I dont know if there is any value in getting this months numbers as we only need to get a value for last month #because we are working out the costs for last month and adding the plan costs to overusage - #numbers that appear in this months stuff should be different in that they are processed with the join date and the prorata is calculated my $datethismonth = UnixDate(ParseDate("15th"),'%b'); my $datelastmonth = UnixDate(DateCalc(ParseDate("15th"), '-1m'),'%b'); my $infile = "/home/httpd/adslinfo/dft-data-upd.$datelastmonth"; my $found = 0; open(PHNUM, $infile) || die "Error opening $infile : $!\n"; while(<PHNUM>) { my $line = $_; $found += 1; @data = split(/,/, $line); my $phone = $data[0]; my $dftcode = $data[1]; my $state = $data[2]; my $datefrom = $data[3]; my $dateto = $data[4]; my $status = $data[5]; my $indata = $data[6]; my $outdata = $data[7]; my $uptill = $data[8]; my $joined = $data[9]; my $plantxt = $data[10]; my $indatamb = int($indata / 1000000); #Do some maths my $outdatamb = int($outdata / 1000000); # print "$data[0] $data[1] $data[2] $data[3] $data[4] $data[5] $data[6] $data[7]$data[8]$data[9]$data[10] $indatamb $outdatamb \n"; #first prepare the query my $sth = $dbh->prepare("select tac_plan, username, billing_email, date_format(udab_date,'%b'), udab_date from _users where adsl_phone='$phone' and tac_plan like 'a%%'"); #then execute $sth->execute; @row = $sth->fetchrow_array(); my $username=$row[1]; my $udab=$row[4]; my $tplan=$row[0]; #if no user report #print "$username \n"; #if exists delete orphan if (!$username) { #you will need to delete the file or the contents on each run because the numbers that existed in the file that dont exist now have been dealt with and secondly numbers would be appended on each run and that be bad open(PORPHAN, ">>/usr/local/tacacts/tmp/orphan-adsl-numbers"); print PORPHAN "$phone \n"; close(PORPHAN); } #print "0 $row[0] 1 $row[1] 2 $row[2] 3 $row[3] 4 $row[4] 5 $row[5]\n"; #you need to nut this out udab is the last time this account was paid #SO you can do MUCH MORE HERE like overdue and never paid come to mind also if its 0 or "" you should put in $joined and work out all the payments from then till now and send an email so we are aware there is an issue if (!$row[4] || $row[4] eq "00-00-0000 00:00:00") { my $sth1 = $dbh->prepare("update _users set udab_date='$joined' where username='terry'"); $sth1->execute; open(BUDAB, ">>/tmp/budab"); print BUDAB "$phone, $joined \n"; close(BUDAB); } $fexist="/usr/local/tacacts/collect/active-plans/$row[0]"; #if it does not exist we REALLY want to know about it so do something here if (-e $fexist) { plancontroler("$outdatamb"); } } And this is the apc.pm subroutine I am calling #!/usr/bin/perl -w package apc; #:defines the name of the package (Like twig) use Exporter; #use this package to make it work @ISA = ('Exporter'); #I think this is some predefined array that you put this package into @EXPORT = ('plancontroler'); #it exports the function below sub plancontroler { #The function we want to export my $outdata=shift; #print "odg $outdata \n"; $plancost = 29.95; if ( $outdata < 201 ) { $extracost = 0; } if (($outdata > 200) && ($outdata < 267)) { $extracost = (($outdata - 200)*.15); } if (($outdata > 266) && ($outdata < 501)) { $extracost = 10; } if (($outdata > 500) && ($outdata < 1001)) { $extracost = 20; } if ($outdata > 1000) { $extracost = 30; } $totalcost = $plancost + $extracost; $plandesc = "ADSL 256/64 Varible"; $acost = 28.60; $extrac = ($outdata * .0055); $wcost = ($acost + $extrac); $profit = ($totalcost - $wcost); my $rdata_ref = shift; #@$rdata_ref= ($totalcost, $plancost, $extracost, $plandesc, $acost, $extrac, $outdata, $wcost, $profit); } 1;
(This post was edited by terry1738 on Mar 13, 2009, 12:46 AM)
|