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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open File handling taking too much time

Status
Not open for further replies.

6681510

Programmer
Aug 29, 2007
16
FI
hi , is there any way to open the file and put it in the ram and use it time to time because i have a code below there iam opening the files too many time thats why my script is taking too much time to complete so is there some thing which iam missing ,

Code:
 # Calculate compansation
################################################################
sub CalculateCompensation{
  my ($strNewType, $strOldType, $intNewSize,$intOldSize,$intMonthsLeft) = @_;
  #This hash will contain OldproductCompensation , New productCompensation,
  #And the compensation which will be smaller.Which needs to be display on the result page.
  my %intPrices;

  #Here we are checking that which size is small cuz the compensation
  #will be given on the bases of small size
  my $intsize;
  if ($intOldSize < $intNewSize){
   $intsize = $intNewSize;
   }
   else {
       $intsize = $intOldSize;
   }
  #Here we are putting the value of small Size to get the
  #vba and then this vba will be used to get the price of the
  #products
  my $VBA = getValueBand($intsize); #old product vba
  my $strOldy1price;#Old Product Year one price
  my $strNewy1price;#New Product Year one price
  my $strOldy2price;#Old Product Year two price
  my $strNewy2price;#New Product Year two price
  my $Compensationy1;
  my $Compensationy2;
  my $Compensationy3;

  ## Compensation is given based on the bases of price
  ########################Getting price for support calculation #################################
  if (($strCase = 4)||($strCase = 5)||($strCase = 6)){
  $strOldy1price = GetPrice($strOldType,'BF1','N',$VBA,'IN',$pricelist);#for first year old product price
  $strNewy1price = GetPrice($strNewType,'BF1','N',$VBA,'IN',$pricelist);#for first year new product price
  $strOldy2price = GetPrice($strOldType,'SU1','N',$VBA,'IN',$pricelist);#for Second year old product price
  $strNewy2price = GetPrice($strNewType,'SU1','N',$VBA,'IN',$pricelist);#for Second year new product price
  }
  if(($strCase = 2)){
  $strOldy1price = GetPrice($strOldType,'BF1','N',$VBA,'IN',$pricelist);#for first year old product price
  $strNewy1price = GetPrice($strNewType,'BF1','N',$VBA,'IN',$pricelist);#for first year new product price
  $strOldy2price = GetPrice($strOldType,'SX2','N',$VBA,'IN',$pricelist);#for Second year old product price
  $strNewy2price = GetPrice($strNewType,'SX2','N',$VBA,'IN',$pricelist);#for Second year new product price
  }
  if(($strCase = 3)){
  $strNewy1price = GetPrice($strNewType,'SU1','N',$VBA,'IN',$pricelist);#for first year new product price
  $strNewy2price = GetPrice($strNewType,'SX2','N',$VBA,'IN',$pricelist);#for first year new product price
  #$strNewy3price = GetPrice($strNewType,'SU3',$VBA);#for first year new product price
  $strOldy1price = GetPrice($strOldType,'SU1','N',$VBA,'IN',$pricelist);#for first year new product price
  $strOldy2price = GetPrice($strOldType,'SX2','N',$VBA,'IN',$pricelist);#for first year new product price
  #$strOldy3price = GetPrice($strOldType,'SU3',$VBA);#for first year new product price
   }
   if  (($strCase ne 1) && ($strOldy1price >= $strNewy1price)){
         $Compensationy1 = $strNewy1price;
   }
    else {$Compensationy1 =$strOldy1price;
     print "First Year Compensation $Compensationy1<br>";
     print "First Year New Compensation $strNewy1price <br>";
     print "First Year New Type $VBA <br>";
    }
   if  (($strCase ne 1) && ($strOldy2price >= $strNewy2price)){
         $Compensationy2 = $strNewy2price;
    }
    else {$Compensationy2 =$strOldy2price}
     print "Second Year Compensation $Compensationy2<br>";
   if  (($strCase ne 1) && ($strOldy3price >= $strNewy3price)){
        $Compensationy3 = $strNewy3price;
    }
    else {$Compensationy3 =$strOldy3price}
  #Now Calculate the result which is greater
  #Old Product Compensation price
  my $strOldCompensation = ($strOldy1price - $strOldy2price);
  print "OldProduct year one $strOldy1price<br>";
  print "OldProdcut year two $strOldy2price<br>";

  #New Product Compensation price
  my $strNewCompensation = ($strNewy1price - $strNewy2price);
  print "NewProduct year one $strNewy1price<br>";
  print "NewProduct year two $strNewy2price<br>";


  my $Compensation;

   #this code will take the price which wil be useed for calculation
  #But compensation will be given on the bases of small price.
  if ($strOldCompensation >= $strNewCompensation)
  {
              $Compensation = $strNewCompensation;

  }
   else
  {
              $Compensation = $strOldCompensation;

  }

  ###########################Now Today we will do this part###################
  #but In which case
  #And in the end what we need to display
  #

  if ($intMonthsLeft >= 0 && $intMonthsLeft <= 12) {
          $intPrices{'s1'} = (1 * ($intOldSize * $Compensationy1)) + (($intMonthsLeft / 12) * ($intOldSize * $Compensationy1));  #Hyvitys for existing license (1) and remaining months ($intMonthsLeft / 12)
  } elsif ($intMonthsLeft >= 13 && $intMonthsLeft <= 24) {
          $intPrices{'s1'} = (1 * ($intOldSize * $Compensationy1) ) + (1 * ($intOldSize * $Compensationy1) );  #Hyvitys for existing license and one full year
          $intPrices{'s2'} = (($intMonthsLeft - 12) / 12) * $intOldSize * ($Compensationy2 );                                                      #Hyvitys for remaining months
  } elsif ($intMonthsLeft >= 25) {
          $intPrices{'s1'} = (1 * ($intOldSize * $Compensationy1) ) + (1 * ($intOldSize * $Compensationy1) );  #Hyvitys for existing license and one full year
          $intPrices{'s2'} = 1 * $intOldSize * &round($Compensationy2 );                                                                                                                                                                   #Hyvitys for one full year
          $intPrices{'s3'} = (($intMonthsLeft - 24) / 12) * $intOldSize * ($Compensationy2 );                                                      #Hyvitys for remaining months
  }

  $intPrices{'strFirstYearSupport'} = sprintf("%2.2f",($intPrices{'s1'}));
  if ($intPrices{'s2'} > 0 ) { $intPrices{'strSecondYearSupport'} = $conf{'currency'}."&nbsp;".sprintf("%2.2f",(-$intPrices{'s2'})); $intPrices{'strSubWithoutMinus2'} = sprintf("%2.2f",($intPrices{'s2'}));} else { $intPrices{'strSecondYearSupport'} = "";}
  if ($intPrices{'s3'} > 0 ) { $intPrices{'strThirdYearSupport'} = $conf{'currency'}."&nbsp;".sprintf("%2.2f",(-$intPrices{'s3'}));} else { $intPrices{'strThirdYearSupport'} = "";}
  $intPrices{'strSecondThirdYearSupport'} = sprintf("%2.2f",($intPrices{'s2'} + $intPrices{'s3'}));  #ex UDF
  $intPrices{'strFirstSecondYearSupport'} = sprintf("%2.2f",($intPrices{'s1'} + $intPrices{'s2'}));  #ex UD2
  $intPrices{'strFirstSecondThirdYearSupport'} = sprintf("%2.2f",($intPrices{'s1'} + $intPrices{'s2'} + $intPrices{'s3'}));  #ex UD3
  ###############################################################################3
  return %intPrices;
  }
 
Some of your "if" conditions look wrong, you are not using the correct operator, example:

Code:
if (($strCase = 4)||($strCase = 5)||($strCase = 6)){

You are using the assingment operator "=" instead of the numeric comparison operator "==". Should be:

Code:
if (($strCase == 4)||($strCase == 5)||($strCase == 6)){

I also see an incorrect operator here:

Code:
if  (($strCase [red]ne[/red] 1)

should be:

Code:
if  (($strCase [red]!=[/red] 1)

So first thing to do is correct all incorrect operators and any other usage problems then retry the code.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top