#!/usr/bin/perl -w use strict 'vars'; my %list; my ($key, $value, $cust, $total); format STDOUT_TOP = +-----------------------------------------------------------------+ | Monthly Recap | |----------------------------+----------+-----------+-------------+ |Account | Prior | Current | Difference | |----------------------------+----------+-----------+-------------+ . format STDOUT = |@<<<<<<<<<<<<<<<<<<<<<<<<<<<|@#####.## | @#####.## | @#####.## | $cust,$list{$cust}->{prior}, $list{$cust}->{new}, $total |----------------------------+----------+-----------+-------------+ . &readfile('sfoct01.txt', 'prior'); # &readfile('sfnov01.txt', 'new'); &printdata; sub readfile{ my ($file, $money) = @_; my ($line, $amount); die unless open FH, $file; while ($line = ){ chomp($line); ($cust, $amount) = split('",',($line)); $cust =~ s/"//g; if (exists $list{$cust}){ $list{$cust}->{$money} += $amount; } else{ $list{$cust}->{$money} = $amount; } $list{$cust}->{new} = 10; } close FH; } sub printdata{ foreach $cust (sort keys %list){ $total = $list{$cust}->{new} - $list{$cust}->{prior}; write; } }