Link to home
Start Free TrialLog in
Avatar of tomasdlv
tomasdlvFlag for United States of America

asked on

How to in C and/or PERL

I have a report that brings back a list of money transactions (positive and negative numbers)

How do write something at the end of the report that gives me a grand total of that list of numbers?

i would like to recieve both C and PERL responses in order to compare.

Avatar of favoretti
Flag of Netherlands image

How do you acquire that report? Is it a tcp connection, a file or what's the input source?
Avatar of tomasdlv


sorry...a little more explaination should have been given.

i am working with Advent Axys (a nightmare) which uses it's own langauge REPLANG to create their reports. The langauge resembles a bit of C and a bit of PERL. My goal is to get some ideas from you guys on how to do this is these langauges and see if i can implement tha same logic in REPLANG.

******I have the REPLANG manual if you like.******

Thanks In Advance.
Avatar of Infinity08
Can you give an example of a report file ? (I assume it's a file ?)
I suppose you could shoot REPLANG manual into me, and I can see if I can come up with a solution in your native language :)
C/Perl solutions would heavily depend on the input source :)
Oh yeah, and the piece of program that generates your current report would be nice as well, so I have some base to work on.
yes...i will attach it...let me know if you get it.
here is the manual

I appreciate the responses.
So, which columns you want to sum up?
Avatar of Adam314

What is the format of the output report?  If it is one transaction per line, and one number per transaction, something like this will work in perl:

#Open file for reading
open(IN, "<file.txt") or die "could not open file: $!\n";
#Create a variable to hold the sum
my $sum = 0;
#Read each line, and process one line at a time
while(<IN>) {
    #Skip lines that do not look like a transaction
    #and save the number for those that do look like a transaction
    next unless /(-?\d+\.\d+)/;
    #Add this number to sum
    $sum += $1;
#Close file
#Print sum
print "The sum is $sum\n";

Open in new window

Just the "Net Amount" column (second to Last)
i have a copy the report and how it looks like on my system.
A bit of a wild guess, since I have no compiler for this naturally, but...

#foo #bucks +

and then print #foo

Would do the trick? :)
Although you might want to initialize #foo at first to 0 or so.
sure i'll give anything a whirl....but where do i out that line and what's #foo?
#foo is just some random variable you create to calculate the sum.
You out that line as the last line of label Output.

i inserted this line...i have an error message see below ...i am also attaching the modified file

Reading \\Epoch23\Advent\Axys3\rep\edletter.rep.
"#bucks" undefined
Bad expression (238):  #bucks +
"#bucks" undefined
Bad expression (238):  #bucks +
"#bucks" undefined
Bad expression (238):  #bucks +
Report edletter completed with warnings.
Hrm... I'll look into it some more. Probably I got the syntax wrong.. All those #$@_~. are sort of crazy :)
Any ideas with this? It's a crazy langauge, right?
It beats me totally. I have no further ideas, mate, I'm really sorry. It would require me to get access to compiler of this to do some trial-and-error. This stuff is REAAAAALLLY not to be written simply on the paper.
I think it should be #_bucks, not #bucks.

Also, is #_bucks always positive?  It looks like it might be, and then whether it was a buy or sell action (so whether #_bucks should be added or subtracted) is stored in $code.  If this is the case, you'll need to move the the line favoretti suggested to different places in the if, and either add or subtract #_bucks.
i have already made the changes to the file to reflect buys are negative and sells are positive....

i need to sum the pool of transactions...maybe a list sum combined with load tran?

did you get the REPLANG pdf above?

Yes. There are some perl modules for reading PDF files.  It might be possible to use one to read the pdf and do the summation there.  I'm looking into this...

It is a shame this program uses it's own language - as this should be something simple in your existing script.

Did you try changing #bucks to #_bucks?  Any difference?
This works on the sample PDF you supplied, giving the sum of the Net Amount.

use CAM::PDF;
my $pdf = CAM::PDF->new(glob("*.pdf"));
my $sum=0;
for(1..$pdf->numPages()) {
	my @lines = split(/\n/, $pdf->getPageText($_));
	shift @lines for(1..4);
	#print join("\n", @lines);
	my $lines = join(" ", @lines);
	#               11-01-07 11-08-07 BUY 100 hty 41013P749 J HANCOCK TAX-ADV GLOBAL SHLDR YIELD FUND    16.1800 1,618.00 0.00 0.00 0.00 1,618.00 brusunknown
	#while($lines =~ /\d+-\d+-\d+\s+\d+-\d+-\d+\s+(BUY)\s+\d+\s+(\w+)\s+\d+\s+([\w\s\n]+)\s+([\d\.,]+){5}\s+([\d\.,]+)\s+\w+/g) {
	while($lines =~
	  /\d+-\d+-\d+\s+              #trade date
	   \d+-\d+-\d+\s+              #settle date
	   ([A-Z]+)\s+                 #activity
	   [\d\.,]+\s+                 #quantity
	   ([\w\.]+)\s+                #symbol
	   [\d\w]+\s+                  #CUSIP
	   ([\w\s\n-]+)\s+             #security
	   ([\d\.,]+\s+){5}            #price, principle, commis, other fee, exchange fee
	   ([\d\.,]+)\s                #net
	   /gx) {
		print "Net=$5\n";
		my $p = $5;
		$p =~ s/,//g;
		$sum += $p;
print "sum=$sum\n";

Open in new window

Yes but i need this in REPLANG...i can provide another file that does the same thing.
Avatar of Adam314

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial