##
#!/usr/bin/perl
use DBI;
use DBD::mysql;
print "Connecting...\n";
my $platform = "mysql";
my $database = "db_name";
my $host = "host_name";
my $port = "port_num";
my $tablename = "hist";
my $user = "user_name";
my $pwd = "pass";
open(STDOUT, ">C:\\perlscripts\\new.txt") || die "Can't open the file";
my $dsn = "dbi:mysql:$database:$host:$port";
my $dbh = DBI->connect($dsn,$user,$pwd) || die "Could not connect: $DBI::errstr\n";
my $query = $dbh->selectall_arrayref("select e_id,cus,ta,gd1,gd2 from hist
order by e_id,cus,ta",
{Slice => {} });
foreach my $ref (@$query) {
print "$ref->{e_id},$ref->{cus},$ref->{ta},$ref->{gd1},$ref->{gd2}\n";
}
Here is the subset of data I get from this code.
Joe,A,1,85,90
Joe,A,1,80,99
Joe,A,2,50,70
Joe,A,2,60,65
Joe,A,2,87,89
Joe,B,1,82,92
Joe,B,3,30,51
Rob,A,1,64,77
Rob,B,2,20,32
####
Joe,A,1,85,90
Joe,A,1,80,99
Total 165,189
Joe,A,2,50,70
Joe,A,2,60,65
Joe,A,2,87,89
Total 147,154
Joe,B,1,82,92
Total 82,92
Joe,B,3,30,51
Total 30,51
Rob,A,1,64,77
Total 64,77
Rob,B,2,20,32
Total 20,32