Guest User

Untitled

a guest
Jan 12th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Perl Database script to Spreadsheet script [closed]
  2. TranID Date AccNum Type Amount ChequeNo DDNo
  3. 657520 02-07-1999 0181432 Debit 16000 465774
  4. 657524 02-07-1999 0181432 Debit 13000 569086
  5. 657538 09-07-1999 0181432 Credit 11000
  6. 657548 18-07-1999 0181432 Credit 15500
  7. 657519 02-07-1999 0181432 Debit 12000
  8. 657523 02-07-1999 0181432 Credit 11000
  9. 657529 03-07-1999 0181433 Debit 15000 466777
  10. 657539 10-07-1999 0181433 Credit 10000
  11. 657541 11-07-1999 0181433 Debit 12000
  12. 657525 03-07-1999 0181433 Debit 15000 569999
  13. 657533 05-07-1999 0181433 Credit 12500
  14.  
  15. #!/usr/bin/perl
  16. use strict;
  17. use warnings;
  18. use DBI;
  19.  
  20. print "content-type:text/htmlnn";
  21.  
  22. my $dbh = DBI->connect('dbi:mysql:database:3306','prithvi','prithvi')
  23. or die "Couldn't connect";
  24.  
  25. my $tran_cur = $dbh->prepare("SQL Query");
  26. $tran_cur->execute;
  27.  
  28. map { print "<td>$_</td>" } qw(AccountNumber-ChequeDebit-DDDebit-CashDebit);
  29. print "<br/>";
  30.  
  31. while (my @data = $tran_cur->fetchrow_array()) {
  32.  
  33. my $rec = join '-', @data;
  34. print "$rec<br/>";
  35. }
  36. $tran_cur->finish;
  37. $dbh->disconnect;
  38.  
  39. AccountNumber-ChequeDebit-DDDebit-CashDebit
  40. 0181432-16000-13000-12000
  41. 0181433-15000-15000-12000
  42.  
  43. #!/usr/bin/perl
  44. use strict;
  45. use warnings;
  46. use DBI;
  47.  
  48. print "content-type:text/htmlnn";
  49.  
  50. my $dbh = DBI->connect('dbi:mysql:database:3306','prithvi','prithvi')
  51. or die "Couldn't connect";
  52.  
  53. my $tran_cur = $dbh->prepare("
  54. SELECT `AccNum`, `Amount`
  55. FROM `database`
  56. WHERE `Type` = 'Debit'
  57. ORDER BY `TranID`;
  58. ");
  59. $tran_cur->execute;
  60.  
  61. print "<br>AccountNumber-ChequeDebit-DDDebit-CashDebit</br>n";
  62.  
  63. my %h;
  64.  
  65. while (my @data = $tran_cur->fetchrow_array()) {
  66. if ($h{$data[0]}) {
  67. $h{$data[0]} .= "-$data[1]";
  68. }
  69. else {
  70. $h{$data[0]} = $data[1];
  71. }
  72. }
  73.  
  74. $tran_cur->finish;
  75. $dbh->disconnect;
  76.  
  77. foreach my $key (sort keys(%h)) {
  78. print "<td>$key" . "-" . $h{$key} . "</td>n";
  79. }
Add Comment
Please, Sign In to add comment