Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 12:23 PM
1DMF's Avatar
1DMF 1DMF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 320 1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 16 h 57 m 54 sec
Reputation Power: 227
Total counter != sum of individual parts?

Hi,

I have a report that uses the following..

Code:
            if($_->{'Category'} eq 'GI'){
                $recs[@recs-1]{'GComp'} = $_->{'Cases'};
                $recs[@recs-1]{'GCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};    
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'GCompVal'};                            
            }
            elsif($_->{'Category'} eq 'Protection'){
                $recs[@recs-1]{'PComp'} = $_->{'Cases'};
                $recs[@recs-1]{'PCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};  
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'PCompVal'};
            }
            else{
                $recs[@recs-1]{'MComp'} = $_->{'Cases'};
                $recs[@recs-1]{'MCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};      
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'MCompVal'};                
            }


What I cannot understand is that if I print the following....
Code:
($recs[0]{'MCompVal'} + $recs[0]{'PCompVal'} + $recs[0]{'GCompVal'})


it does not add up to 'CompVal'?

How is this happening, the code that calculates 'CompVal' is the same place where the individual sums are calculated 'GCompVal' , 'PCompVal', 'MCompVal' , so therefore 'GCompVal' + 'PCompVal' + 'MCompVal' should = 'CompVal' but it doesn't?

What on earth is going on?

Thanks,
1DMF
__________________
Free MP3 Dance Music Downloads

To err is human; To really balls things up you need Microsoft!

Reply With Quote
  #2  
Old October 29th, 2012, 01:58 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 507 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 10 m 26 sec
Reputation Power: 385
Quote:
Originally Posted by 1DMF
What I cannot understand is that if I print the following....
Code:
($recs[0]{'MCompVal'} + $recs[0]{'PCompVal'} + $recs[0]{'GCompVal'})


it does not add up to 'CompVal'?



Is it supposed to be the case?

I would think that

Code:
($recs[0]{'MCompVal'} + $recs[0]{'PCompVal'} + $recs[0]{'GCompVal'})


would add possibly to

Code:
$recs[0]{'CompVal'}


but there is nothing in your code which would lead to think that it should add to ComVal.

Reply With Quote
  #3  
Old October 29th, 2012, 02:04 PM
1DMF's Avatar
1DMF 1DMF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 320 1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 16 h 57 m 54 sec
Reputation Power: 227
$recs[@recs-1] = $recs[0]

They are the same thing as it is a single indexed array with a hash in it.

CompVal is a running total , which should equal the sum of the other 3 totals but it doesn't and I don't undertsand why.

Could it be a rounding thing or a float issue ?

Though it is out by nearly £2,000.00?

Reply With Quote
  #4  
Old October 29th, 2012, 02:27 PM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
Hard to know for sure without seeing the code in context.

From what you've posted, I'd check that some of those values aren't being set twice. Any time a GCompVal, PCompVal or MCompVal is set, any previous value in those is overwritten, whereas the CompVal is incremented each time. If your code sets a GCompVal (for example) twice, then only the second value will be store in GCompVal whereas CompVal will have added both values.

Reply With Quote
  #5  
Old October 29th, 2012, 02:54 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 507 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 10 m 26 sec
Reputation Power: 385
Quote:
Originally Posted by 1DMF
$recs[@recs-1] = $recs[0]


That bit, I understood from your code and comments. But why do you need an array if subscript is always 0?

Quote:
CompVal is a running total , which should equal the sum of the other 3 totals but it doesn't and I don't undertsand why.

'CompVa'l is a litteral representing a string of characters, not a numeric total. 'CompVa'l is bound not to be equal to you sum. Please indicate clearly what is not equal to you sum of three values.

Quote:
Could it be a rounding thing or a float issue ?

Though it is out by nearly £2,000.00?


I don't think so.

Use the debugger, or print the values of your variables before and after the piece of code you posted, or post more of your code. From what you posted, we do not have enough information. The problem, if any, is probably somewhere else.

Reply With Quote
  #6  
Old October 30th, 2012, 05:03 AM
1DMF's Avatar
1DMF 1DMF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 320 1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 16 h 57 m 54 sec
Reputation Power: 227
Hey ishnid, how the devil are you? Long time no speak

Should we call you Professor from now on

Laurent, not sure why you believe the total is a string literal, but anyway, here is the output from data dumper.

The first is @subs, the second is @recs.

Quote:
$VAR1 = { 'Value' => '145.0000', 'Cases' => '1', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'SUB', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'GI' }; $VAR2 = { 'Value' => '800.0000', 'Cases' => '1', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'SUB', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'Non-Reg Mortgage' }; $VAR3 = { 'Value' => '2082.0000', 'Cases' => '2', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'SUB', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'Protection' }; $VAR4 = { 'Value' => '4527.0000', 'Cases' => '6', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'SUB', 'Adviser' => 'David xxxx', 'Fees' => '297.0000', 'Category' => 'Reg Mortgage' }; $VAR5 = { 'Value' => '2033.0300', 'Cases' => '17', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'COMP', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'GI' }; $VAR6 = { 'Value' => '3150.0000', 'Cases' => '5', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'COMP', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'Non-Reg Mortgage' }; $VAR7 = { 'Value' => '2666.0000', 'Cases' => '8', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'COMP', 'Adviser' => 'David xxxx', 'Fees' => '.0000', 'Category' => 'Protection' }; $VAR8 = { 'Value' => '31833.7000', 'Cases' => '59', 'Costs' => '.0000', 'Adv_MemNo' => 'Mxxxx-0xx', 'Type' => 'COMP', 'Adviser' => 'David xxxx', 'Fees' => '2773.0000', 'Category' => 'Reg Mortgage' };
--------------------------------------------------------------------------------
$VAR1 = { 'GCompVal' => '2033.03', 'PSub' => '2', 'SubVal' => 7851, 'PSubVal' => 2082, 'Leave' => '*', 'Adv_MemNo' => 'Mxxxx-0xx', 'Join' => '31/10/2011', 'GComp' => '17', 'PCompVal' => 2666, 'MSubVal' => 4824, 'MCompVal' => '34606.7', 'MComp' => '59', 'CompVal' => '42455.73', 'Adviser' => 'David xxxx', 'MSub' => '6', 'CompanyName' => undef, 'GSub' => '1', 'GSubVal' => 145, 'PComp' => '8' };


here is the code...
Code:
#loop and build data
    for(@subs){
                      
        # check if next broker
        if(!@recs || $recs[@recs-1]{'Adviser'} ne $_->{'Adviser'})
        {
            # set start / leave dates
            $mdate{$_->{'Adv_MemNo'}} = substr($mdate{$_->{'Adv_MemNo'}},0,10);
            if($ldate{$_->{'Adv_MemNo'}} eq ""){$ldate{$_->{'Adv_MemNo'}} = "*";}
            else{ 
                $ldate{$_->{'Adv_MemNo'}} = substr($ldate{$_->{'Adv_MemNo'}},0,10);
                my @ldate = split(/-/, $ldate{$_->{'Adv_MemNo'}});
                $ldate{$_->{'Adv_MemNo'}} = $ldate[2] . "/" .  $ldate[1] . "/" .  $ldate[0];  
            }
            my @mdate = split(/-/, $mdate{$_->{'Adv_MemNo'}});
            $mdate{$_->{'Adv_MemNo'}} = $mdate[2] . "/" .  $mdate[1] . "/" .  $mdate[0];
          
            push (@recs,{'Adv_MemNo' => $_->{'Adv_MemNo'},'Adviser' => $_->{'Adviser'},'CompanyName' => $_->{'CompanyName'},'Join' => $mdate{$_->{'Adv_MemNo'}},'Leave' => $ldate{$_->{'Adv_MemNo'}}});         
            $recs[@recs-1]{'MSub'} = 0;      
            $recs[@recs-1]{'MSubVal'} = 0;                
            $recs[@recs-1]{'MComp'} = 0;      
            $recs[@recs-1]{'MCompVal'} = 0;             
            $recs[@recs-1]{'GSub'} = 0;      
            $recs[@recs-1]{'GSubVal'} = 0;  
            $recs[@recs-1]{'GComp'} = 0;      
            $recs[@recs-1]{'GCompVal'} = 0;          
            $recs[@recs-1]{'PSub'} = 0;      
            $recs[@recs-1]{'PSubVal'} = 0;               
            $recs[@recs-1]{'PComp'} = 0;      
            $recs[@recs-1]{'PCompVal'} = 0;           
            $recs[@recs-1]{'SubVal'} = 0;      
            $recs[@recs-1]{'CompVal'} = 0;                         
        }

        if($_->{'Type'} eq 'SUB'){
            
            if($_->{'Category'} eq 'GI'){
                $recs[@recs-1]{'GSub'} = $_->{'Cases'};
                $recs[@recs-1]{'GSubVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};                               
            }
            elsif($_->{'Category'} eq 'Protection'){
                $recs[@recs-1]{'PSub'} = $_->{'Cases'};
                $recs[@recs-1]{'PSubVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};                
            }
            else{
                $recs[@recs-1]{'MSub'} = $_->{'Cases'};
                $recs[@recs-1]{'MSubVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};      
            }        
            
            $recs[@recs-1]{'SubVal'} +=  (($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'});   
                            
        }
        else{
        
            if($_->{'Category'} eq 'GI'){
                $recs[@recs-1]{'GComp'} = $_->{'Cases'};
                $recs[@recs-1]{'GCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};    
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'GCompVal'};                            
            }
            elsif($_->{'Category'} eq 'Protection'){
                $recs[@recs-1]{'PComp'} = $_->{'Cases'};
                $recs[@recs-1]{'PCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};  
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'PCompVal'};
            }
            else{
                $recs[@recs-1]{'MComp'} = $_->{'Cases'};
                $recs[@recs-1]{'MCompVal'} = ($_->{'Value'} + $_->{'Fees'}) - $_->{'Costs'};      
                $recs[@recs-1]{'CompVal'} += $recs[@recs-1]{'MCompVal'};                
            }
  
        }
        
    }

    # sort results by Adviser 
    @recs = sort { $a->{'Adviser'} cmp $b->{'Adviser'} } @recs; 
    
    
    use Data::Dumper;
    print '<!--T--> <hr>' . Dumper(@subs) . '<hr>' . Dumper(@recs)


You will see that the total for CompVal = 42455.73 but the sum of the other 3 totals = 39305.73 ?

I've even moved the 'Comp' total counter to inside the 3 if statements to be sure that when a value is added to either of the sub totals, it also includes the grand total, you will see how it was originally for the subs, as I have left that counter as is. Which incidently is out by exactly 800?

I did a simple output of the records as they were looped in @subs...
Quote:
Value = 145.0000, Fees = .0000 , Costs = .0000 , Type = SUB, Cat = GI

Value = 800.0000, Fees = .0000 , Costs = .0000 , Type = SUB, Cat = Non-Reg Mortgage

Value = 2082.0000, Fees = .0000 , Costs = .0000 , Type = SUB, Cat = Protection

Value = 4527.0000, Fees = 297.0000 , Costs = .0000 , Type = SUB, Cat = Reg Mortgage

Value = 2033.0300, Fees = .0000 , Costs = .0000 , Type = COMP, Cat = GI

Value = 3150.0000, Fees = .0000 , Costs = .0000 , Type = COMP, Cat = Non-Reg Mortgage

Value = 2666.0000, Fees = .0000 , Costs = .0000 , Type = COMP, Cat = Protection

Value = 31833.7000, Fees = 2773.0000 , Costs = .0000 , Type = COMP, Cat = Reg Mortgage


using
Code:
        print "<p>Value = $_->{'Value'}, Fees = $_->{'Fees'}) , Costs =  $_->{'Costs'} , Type =  $_->{'Type'}, Cat = $_->{'Category'}</p>";             


And if you add up the 4 'Sub' record values you get 7554, then minus the 297 fee = 7257, yet the SubVal = 7851.

None of the figures are adding up, why?

Last edited by 1DMF : October 30th, 2012 at 05:29 AM.

Reply With Quote
  #7  
Old October 30th, 2012, 10:16 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
Quote:
Originally Posted by 1DMF
Hey ishnid, how the devil are you? Long time no speak

Should we call you Professor from now on

Not yet, unfortunately. Hopefully, 'doctor' will apply by January though! Hope you're keeping well.


Quote:
Originally Posted by 1DMF
And if you add up the 4 'Sub' record values you get 7554, then minus the 297 fee = 7257, yet the SubVal = 7851.

I think this is the key. I suspect it's not a coincidence that 7554+297=7851 but what you want is 7554-297=7257. It looks like you're adding on the fees instead of subtracting them. Could that be the issue, or am I misreading?

As an aside, when posting Data:umper output, it's easier for someone like me to do something with the data if you dump a reference to the array, i.e. print Dumper(\@recs);

Reply With Quote
  #8  
Old October 30th, 2012, 10:54 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,645 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 51 m 15 sec
Reputation Power: 1170
Quote:
$recs[@recs-1] = $recs[0]

They are the same thing ...
No, they are not.

When using @recs-1 as the array index, which BTW is a very poor coding practice, you're specifying the last element of the array, not the first. If the array only contains a single element then, yes, 0 and @recs-1 refer to the same element, but you shouldn't confuse the issue by using that syntax.

If you want to refer to the last element, then the proper syntax would be:
Code:
$recs[-1]


So, in your posted code snippets, did you really want the last element of @recs, or the first element?

Currently, @recs ends up with only 1 element. Will that always be the case? If so, then why use an array?

Reply With Quote
  #9  
Old October 30th, 2012, 01:58 PM
1DMF's Avatar
1DMF 1DMF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 320 1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level)1DMF User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 3 Days 16 h 57 m 54 sec
Reputation Power: 227
Fishmonger ->
Quote:
$recs[-1]
didn't know that many thanks. (I've updated the code)

And of course there isn't always 1 , hence the array!

ishnd ->

cool well done and congratulations Dr. Isnid :-)

as to the total ...hmm, I've confused myslef here!

The sub total is meant to be 7851, yes it's (value + fees) - costs

sorry, but the point is the output shows subval as 7,851 but each group total (MSubVal + GSubVal + PSubVal) = 7051? instead of 7851 ? 800 short, which is interesting because that's exactly the value of the case (Non-Reg Mortgage) 800?

I've checked and @recs is size 1, where is this value going astray?

How are the grand totals correct but the sum of the parts don't equal the total?

Edit -> finally the penny drops!

It should be...

Code:
               if($case->{'Status'} eq 'SUB'){
            
            if($case->{'Category'} eq 'GI'){
                $recs[-1]{'GSub'} += $case->{'Cases'};
                $recs[-1]{'GSubVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                                                              
            }
            elsif($case->{'Category'} eq 'Protection'){
                $recs[-1]{'PSub'} += $case->{'Cases'};
                $recs[-1]{'PSubVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                                               
            }
            else{
                $recs[-1]{'MSub'} += $case->{'Cases'};
                $recs[-1]{'MSubVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                    
            }                              
                         
            $recs[-1]{'SubVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                            
        }
        else{
        
            if($case->{'Category'} eq 'GI'){
                $recs[-1]{'GComp'} += $case->{'Cases'};
                $recs[-1]{'GCompVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                              
            }
            elsif($case->{'Category'} eq 'Protection'){
                $recs[-1]{'PComp'} += $case->{'Cases'};
                $recs[-1]{'PCompVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});  
            }
            else{
                $recs[-1]{'MComp'} += $case->{'Cases'};
                $recs[-1]{'MCompVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});                     
            }
  
            $recs[-1]{'CompVal'} += (($case->{'Value'} + $case->{'Fees'}) - $case->{'Costs'});
        }


Man, roll on Christmas, coz I clearly need a break!

(Fishmonger - you'll notice I tidied up the code for you )
Comments on this post
ishnid agrees: Glad you got it sorted out.

Last edited by 1DMF : October 30th, 2012 at 02:23 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Total counter != sum of individual parts?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap