6 $mydir = `cd \$(dirname $0) 2>/dev/null; pwd`; chomp($mydir);
7 unshift @INC,("$mydir/../setup");
8 if( -f "$mydir/../setup/db_config.local") { require "db_config.local"; }
9 else { require "db_config"; }
11 %hometeaching_data = ();
12 %membership_data = ();
15 $monthname2num{'Jan'} = '01';
16 $monthname2num{'Feb'} = '02';
17 $monthname2num{'Mar'} = '03';
18 $monthname2num{'Apr'} = '04';
19 $monthname2num{'May'} = '05';
20 $monthname2num{'Jun'} = '06';
21 $monthname2num{'Jul'} = '07';
22 $monthname2num{'Aug'} = '08';
23 $monthname2num{'Sep'} = '09';
24 $monthname2num{'Oct'} = '10';
25 $monthname2num{'Nov'} = '11';
26 $monthname2num{'Dec'} = '12';
28 ######################################################################
30 ######################################################################
33 my ($filename, $hashref) = @_;
35 open(FILE,$filename) || die "-E- Could not open $filename for reading\n";
37 my $found_header = 0; my $index = 0;
41 @data = split /\",/, $line;
42 if(!$found_header) { @header = @data; $found_header = 1; }
44 foreach $i (0..$#data-1) {
46 $header[$i] =~ s/\"//g;
47 $hashref->{$index}{$header[$i]} = $data[$i];
48 #print "$index: $i: $header[$i]: $data[$i]\n";
57 ######################################################################
62 foreach $key (sort {$a <=> $b} keys %$hashref) {
63 print "Index: $key\n";
64 foreach $field (keys %{$hashref->{$key}}) {
65 print "$field: $hashref->{$key}{$field}\n";
71 ######################################################################
76 foreach $key (sort {$a <=> $b} keys %$hashref) {
79 foreach $field (keys %{$hashref->{$key}}) {
80 if($field =~ /Full Name/) { $name = $hashref->{$key}{$field}; }
81 if($field =~ /Birth/) { $birthday = $hashref->{$key}{$field}; }
83 if($name ne "" && $birthday ne "") { printf "%-30s %-10s\n",$name,$birthday; }
87 ######################################################################
89 ######################################################################
91 ###################################################
92 # Open a connection to the database
93 $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$dbpass,{
95 PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
97 ###################################################
98 # Process command line options
99 if(defined $opt_n) { $datadir = $opt_n; }
100 else { $datadir = shift(@ARGV); }
101 print "-> Processing all ward data files in $datadir\n";
103 ###################################################
104 # Parse Ward Data Files
105 &csv_to_hash("$datadir/Membership.csv",\%membership_data);
106 &csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data);
109 print "-> Membership Data Dump\n\n";
110 &print_hash(\%membership_data);
111 print "-> HomeTeaching Data Dump\n\n";
112 &print_hash(\%hometeaching_data);
115 if($opt_b) { &print_birthdays(\%membership_data); }
117 if($opt_s) { $dbh->disconnect(); exit; }
119 ###################################################
120 # Disconnect from the database
123 ######################################################################