Hi experts,help!!
I am reading data from a text file and storing the data in an array of hashes and hash
of hashes.I dont know how and where I need to pass the reference into the array and
hash and dereference it.
The purpose of the code is to read data by column names and compare each record with a
record from another text file.Could someone help me .Thank you. Naveen
I am sorry about the amount,style of code I am enclosing.
# File to do the compare
sub compare {
my ($record_type,$raima_file,$db2_file) =@_;
print "raima file :$raima_file\n";
# my $raima_file = "raima_profile.txt";
# my $db2_file = "db2profile.txt";
my @db2array;
my %hashb_outer;
my %hasha_outer;
open (RAIMA,$raima_file)
or die "Cannot open file $raima_file\n";
print "Comparing raima and db2 profile files\n";
while( my $raimadata = <RAIMA>) {
my @line_a;
my %hash_a;
chop $raimadata;
$raimadata =~ s/\"//g;
@line_a = split(/\|/,$raimadata);
my @raimafields = &get_raima_field_names($record_type);
while (@raimafields){
my $raimafieldname = shift @raimafields;
# print "raima field name is $raimafieldname \n";
$hash_a{$raimafieldname} = shift @line_a;
# print "raima hash value is $hash_a{$raimafieldname} \n";
#push(@raimaarray,\%hash_a);
} #end while of raimafields
my $raimaid = "profile"." ".$hash_a{"profile_user_id"}." ".$hash_a{"profile_country"};
$hasha_outer{$raimaid} = \%hash_a;
}
open (DB2,$db2_file)
or die "Cannot open file $db2_file\n";
while( my $db2data = <DB2>) {
my @line_b;
my %hash_b;
chop $db2data;
$db2data =~ s/\"//g;
@line_b = split(/\|/,$db2data);
my @db2fields = &get_db2_field_names($record_type);
while (@db2fields){
my $db2fieldname = shift @db2fields;
# print "db2 field name is $db2fieldname \n";
$hash_b{$db2fieldname}= shift @line_b;
# print "db2 hash value is $hash_b{$db2fieldname} \n";
}
my $db2id = "profile"." ".$hash_b{"profile_user_id"}." ".$hash_b{"profile_country"};
$hashb_outer{$db2id} = \%hash_b;
}
&printRecDiffs(\@db2array,\%hasha_outer,$record_type);
} #end of compare
sub printRecDiffs {
my ($db2array,$hashRaima,$record_type) =@_;
my %ignored_fields = &get_ignored_fields($record_type);
my %char_fields = &get_char_fields($record_type);
for $i (0..$#{$db2array})
{
my %db2hash1 = %{$$db2array[$i]};
my $id;
# if($record_type eq "profile"){
$id= "profile"." ".$db2hash1{"profile_user_id"}." ".$db2hash1{"profile_country"};
# print "inside profile id value is $id\n";
# }
# print "check after char fields \n";
if (exists $$hashRaima{$id})
{
my %raimahash = %{$$hashRaima{$id}};
foreach $db2key (keys %db2hash1)
{
# print "the value for the key $db2key is $db2hash1{$db2key}\n";
if ($ignored_fields{$db2key})
{
print "ignored fieldname is $db2key :$ignored_fields{$db2key}\n";
next;
}
if ($char_fields{$db2key}) {
print "char field name is $db2key :$char_fields{$db2key} \n";
$raimahash{$db2key} = chr($raimahash{$db2key});
}
if( $db2hash1{$db2key} ne $raimahash{$db2key})
{
# print the differences
if($db2hash1{$db2key} =~ /[+-]?\d+\.?\d*$/ )
{
if($db2hash1{$db2key} != $raimahash{$db2key})
{
print "numeric \n";
print "the key is $db2key\n";
print " db2 value is $db2hash1{$db2key}\n";
print " raima value is $raimahash{$db2key}\n";
}
}
else
{
print "the key is $db2key\n";
print " db2 value is $db2hash1{$db2key}\n";
print " raima value is $raimahash{$db2key}\n";
}
} #if
} #foreach
} #if
else {
print "The record doesnt exist in Raima\n";
}
} #for
}
end of code
---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site