Am Mittwoch, 11. Mai 2005 15.18 schrieb Mark Martin:
> HI,
> I want to provide remittance slips to my suppliers. I've extracted data
> from my payments database and pushed records into an array. Here is a
> sample of data from that array :
>
> 01,supplierA,100.00,1st May 2005
> 02,supplierB,100.00,3rd May 2005
> 03,supplierC,100.00,3rd May 2005
> 04,supplierA,100.00,4th May 2005
>
> I would identify the fields thus :
>
> foreach $item(@array) {
> ($transaction,$supplier,$amount,$pay_date) = split /,/,$item;
> }
>
> This allows me to print a remittance by transaction(record) but I need some
> sort of grouping mechanism to group transactions belonging to the same
> supplier.
> In other words - although the sample above has 4 transactions, it should
> only produce 3 remittance slips.
What about something like the following (the code could be shorter):
my %suppliers;
foreach $item(@array) {
($transaction,$supplier,$amount,$pay_date) = split /,/,$item;
# record sum of amounts
$suppliers{$supplier}->{amount}+=$amount;
# record transactions
push @{$suppliers{$supplier}->{transactions}}, $transaction;
# record pay dates
push @{$suppliers{$supplier}->{pay_dates}}, $pay_date;
}
joe
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>