[Solved] Database – SQL Table to Perl Script

Introduction

Solution


If you add use strict and use warnings you’ll probably get some feedback about needing to declare @tran in the code below:

while(my @row = $tran->fetchrow_hash) 
{
    my $tran = join ',', @row;
    $trans{$tran[2]}{$tran[3]} += $tran[4];
}

$tran is 657520,02-07-1999,016901581432,Debit,16000 when you try and use it as an array.

Use Data::Dumper to show what you put into %trans at the end:

use Data::Dumper;
print Dumper(\%trans);

Did you mean:

while(my @row = $tran->fetchrow_array) 
{
    $trans{$row[2]}{$row[3]} += $row[4];
}

1