I am a Perl beginner and I am not familiar with hashes, I have read 2 csv files into 2 hahes.
I want to check the data in %balance against %account and validate following rules
• Any account with a balance greater than zero that was due before Oct 23, 2007 has an overdue value of 1
• Any account without an overdue balance has a NULL overdue value (empty in the csv files) or an overdue value of 0
print accounts from %account hash with errors
********** BALANCE DATA ***************
$VAR1 = {
'1' => {
'due_date' => '11/28/2007 15:54',
'balance' => '482.29',
'account' => 'ar161429'
},
'3' => {
'due_date' => '10/23/2007 15:54',
'balance' => '887.78',
'account' => 'ar106644'
},
'id' => {
'due_date' => 'balance_due',
'balance' => 'balance',
'account' => 'account_number'
},
'2' => {
'due_date' => '10/9/2007 15:54',
'balance' => '266.93',
'account' => 'ar182364'
}
};
********** ACCOUNT DATA ***************
$VAR1 = {
'21' => {
'account' => 'ar465032',
'cdate' => '1/2/2007 15:36',
'name' => 'Justine Lafortune',
'odue' => ''
},
'7' => {
'account' => 'ar161429',
'cdate' => '3/7/2007 15:36',
'name' => 'Woody Harding',
'odue' => '0'
},
'10' => {
'account' => 'ar182364',
'cdate' => '12/1/2006 15:36',
'name' => 'Mayson Gettemy',
'odue' => '1'
},
'id' => {
'account' => 'account_number',
'cdate' => 'created_date',
'name' => 'name',
'odue' => 'overdue'
},
'20' => {
'account' => 'ar106644',
'cdate' => '4/6/2007 15:36',
'name' => 'Reina Garratt',
'odue' => '1'
}
};
***********************************************************
My Program below
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Date::Calendar::Year;
my %balance;
my %account;
print "********** BALANCE DATA ***************\n";
bal_file();
print "********** ACCOUNT DATA ***************\n";
acct_file();
sub bal_file
{
open my $bal_fh, '<', 'b.csv' or die "failed to open a.csv $!";
while (my $line = <$bal_fh>) {
chomp $line;
my ( $id,$account_number, $balance, $due) = split /,/, $line,4;
$balance{$id} = {
account => $account_number,
balance => $balance,
due_date => $due
}
}
close $bal_fh;
print Dumper \%balance;
}
sub acct_file
{
open my $act_fh, '<', 'a.csv' or die "failed to open a.csv $!";
while (my $line = <$act_fh>) {
chomp $line;
my ( $id,$full_name,$created_date,$account_number, $overdue) = spl
+it /,/, $line,5;
$account{$id} = {
name => $full_name,
cdate => $created_date,
account => $account_number,
odue => $overdue
}
}
close $act_fh;
print Dumper \%account;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.