[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Total and sub total value for the period and by client name

Posted on 2006-03-27
11
Medium Priority
?
182 Views
Last Modified: 2010-03-05
For the script below;
A- How to resolve the Error message "Use of uninitialized value in concatenation (.) or string" ( I think it is todo with $ sign)
B- I need to know how I can get the TOTAL $ value for the period and SUBTOTAL $ value for the name for example
Francesca Voolvo 07/03/2005 710 $0.00 $153.00
Francesca Voolvo 07/03/2005 940 $0.00 $98.00
                           Total value for the period 07/03/2005 is $251    # that is ($153+98=251)
Francesca Voolvo 07/03/2004 940 $0.00 $198.00
                           Subtotal for Francesca is $449                         # subtotal is Total value above + $198= $49

Anna smith 08/02/2005 600 $0.00 $113.00
Anna smith 08/03/2005 640 $0.00 $1,109.00
                           Total value for the period 07/03/2005 is $1222
                            Subtotal for Anna is $1222

My script is

my $datafile= "c:/mydir/last.txt";
my $clients= "c:/mydir/clients.txt";
open( CLIENTS, "< $clients" ) or die "Can't open $clients : $!";
my @fields= ();
while($_= <CLIENTS> ){
@fields = split ' ';
my $customer = "$fields[0] $fields[1] $fields[2]";
my @mynames = "$fields[0] $fields[1] $fields[2]";
open( DATAFILE, "< $datafile" ) or die "Can't open $datafile : $!";
my @datafile= ();
while($_ = <DATAFILE> ){
  if(/$customer/) {
@datafile = split ' ';
print  "$datafile[0] $datafile[1] $datafile[2] $datafile[5] $datafile[6] $datafile

[7] $datafile[8]\n";
}
}
close DATAFILE;
}
close CLIENTS;

-------------------------------------
THE CURRENT OUTPUT OF THE SCRIPT IS

Francesca Voolvo 07/03/2005 710 $0.00 $153.00
Francesca Voolvo 07/03/2005 940 $0.00 $98.00
Francesca Voolvo 07/03/2004 940 $0.00 $198.00
Anna smith 08/02/2005 600 $0.00 $113.00
Anna smith 08/03/2005 640 $0.00 $1,109.00
john WWWW 23/02/2006 600 $0.00 $113.00
Use of uninitialized value in concatenation (.) or string at jj5.pl line 15, <DA
TAFILE> line 803.
Use of uninitialized value in concatenation (.) or string at jj5.pl line 15, <DA
TAFILE> line 803.
john WWWW 16/03/2006 640
Jeffory plee 06/03/2006 600 $0.00 $113.00
Yacoub Mercie 08/02/2006 722 $0.00 $185.15
Florence floor 30/11/2005 700 $0.00 $59.00
Florence floor 30/11/2005 800 $0.00 $113.00
Florence floor 21/12/2005 840 $0.00 $387.00
MARTA lee 19/12/2005 722 $0.00 $0.00
MARTA lee 19/12/2005 940 $0.00 $0.00


0
Comment
Question by:lonaj
  • 6
  • 5
11 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 16301388
what is line 803 of in c:/mydir/last.txt?
is there really a blank line between $datafile
and
[7]

0
 
LVL 85

Expert Comment

by:ozo
ID: 16303017
does c:/mydir/last.txt line 803 have 9 fields?
0
 

Author Comment

by:lonaj
ID: 16306522
line 803 does not have field 7 and 8
803:          john WWWW        xxxxxxxx xxxxxx 16/03/2006     640

So if I take out fileds 7 and 8 (print  "$fields[1] $fields[2] $fields[5] $fields[6]\n";) I do not get the error message


does c:/mydir/last.txt line 803 have 9 fields?
a line in last.txt file may contain 9 fileds or more or less in this case is less
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 85

Expert Comment

by:ozo
ID: 16306584
You might try
print "$fields[1] $fields[2] @fields[5..$#fields]\n";
which will print just the fields after 5 that do exist.
Would you want to consider fields that don't exist to be $0.00 for totaling purposes?

Is c:/mydir/clients.txt small enough to fit in memory so you don't have to open and read through the whole file multiple times?
0
 
LVL 85

Expert Comment

by:ozo
ID: 16309101
is /$customer/ supposed to match particular fields in <DATAFILE>?  if so, which fields?
are the records in <DATAFILE> that match the same /$customer/ the records that you want grouped together for TOTAL and SUBTOTAL?
0
 

Author Comment

by:lonaj
ID: 16311154
Yes the records in <DATAFILE> that match the same /$customer/ the records that I want o groupe together for TOTAL and subtotal, (TOTAL by name, Date Service).

as per below (is /$customer/ supposed to match particular fields in <DATAFILE>?  if so, which fields?)
/$customer/ match  $fields[0] $fields[1] $fields[2] on <DATAFILE>

lients.txt contain the name of the clients for example
Mrs. Olga Doo
Mr Henry Fox
MRS. SERAH FOSTER

example of <DATAFILE>
some info xxxxxxx xxxxx
xxxxxx  xxxxx
filed0,1,2            field[3]        field[4]             field[5]       filed[6]  field[7]   filed[8]
Client name        Client_No     IDnumber-2     Date service   Item    GST        Benefit      
Mrs. Olga Doo    FAI0-105      2248A7721F    29/11/2005     722    $0.00        $0.00
Ms. Sue Jake       JK3930T      1234
xxxxxxxxxxSome data xxxxxxxxxxxx
some info xxxxxxx xxxxx
xxxxxx  xxxxx
Mr Henry Fox       KLM0-305      ABCD8A77    29/11/2005     992    $10.00        $350.00
Mr Henry Fox       KLM0-305      ABCD8A77    4/10/2005       878    $.00            $50.00
some data xxxxxxxxx xxxxx          xxxxxxxxxx          xxxxxxxx
 
0
 

Author Comment

by:lonaj
ID: 16340424
any help on this question please ?
0
 
LVL 85

Expert Comment

by:ozo
ID: 16352128
my $datafile= "c:/mydir/last.txt";
my $clients= "c:/mydir/clients.txt";
open( DATAFILE, "< $datafile" ) or die "Can't open $datafile : $!";
my %data;
while( <DATAFILE> ){
    my @fields = split;
    push @{$data{"@fields[0..2]"}},[@fields[5..8]] if $#fields>=8;
}
close DATAFILE;
open( CLIENTS, "< $clients" ) or die "Can't open $clients : $!";
while($_= <CLIENTS> ){
    my @fields = split;
    if( my $data = $data{my $customer="@fields[0..2]"} ){
        my $total=0;
        my $subtotal=0;
        my $prevdate;
        for( @$data ){
            if( $prevdate && $prevdate ne $_->[0] ){
                printf("\tTotal value for the period %s is %.2f\n",$prevdate,$subtotal);
                $subtotal=0;
            }
            print "$customer @$_\n";
            my($v)=($_->[3]||0)=~/\D*([\d.]*)/;
            $subtotal += $v;
            $total += $v;
            $prevdate=$_->[0];
        }
        printf("\tTotal value for the period %s is \$%.2f\n",$prevdate,$subtotal) if $subtotal;
        printf("\tSubtotal for %s is \$%.2f\n",$customer,$total);
       
    }
}
close CLIENTS;
0
 

Author Comment

by:lonaj
ID: 16352536
Thank you OZO that works fine, Except when there is $1000 or more on field[8] (benefit) it print as $1 the result also subtotal will be wrong
see bellow for example for (Anna mils,John MOORE)

Ms. Anna mils 08/02/2006 600 $0.00 $113.00
        Total value for the period 08/02/2006 is 113.00
Ms. Anna mils 08/03/2006 640 $0.00 $1,109.00
        Total value for the period 08/03/2006 is $1.00 <------  from $1,109.00
        Subtotal for Ms. Anna VORBOJOV is $114.00   <----- $113+$1,109.00 ?

Mr. John MOORE 22/02/2006 600 $0.00 $113.00
        Total value for the period 22/02/2006 is 113.00
Mr. John MOORE 15/03/2006 640 $0.00 $1,215.00
        Total value for the period 15/03/2006 is $1.00 <------- from $1,215.00
        Subtotal for Mr. Eric MOORE is $114.00           <------- $113+$1,215.00 ?

MRS. JULIE Sink 25/01/2006 722 $0.00 $185.15
        Total value for the period 25/01/2006 is 185.15
MRS. JULIE Sink 07/03/2006 850 $0.00 $741.00
        Total value for the period 07/03/2006 is $741.00
        Subtotal for MRS. JULIE LOTTORTO is $926.15
0
 
LVL 85

Accepted Solution

by:
ozo earned 200 total points
ID: 16358436
          my($v)=($_->[3]||0)=~/\D*([\d.,]*)/;
           $v=~/,//g;
0
 

Author Comment

by:lonaj
ID: 16367336
yes ozo that worked,thanks for all support and followup

Note** using the line $v=~/,//g; ## gives the following error message;

Unquoted string "g" may clash with future reserved word at mypl.pl line 27.
Useless use of division (/) in void context at mypl.pl line 27.
Argument "g" isn't numeric in division (/) at mypl.pl line 27, <CLIENTS> line 1

Illegal division by zero at mypl.pl line 27, <CLIENTS> line 1.

I have changed the line from $v=~/,//g; TO $v=~s/,//g; ## and worked fine

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question