Hello,
Right now I have a hash with keys that have values but if I want to add another value to the hash key it overwrites the value already stored there. Is there anyway to make it so that I can store more than one value for a particular key? Below is the code that I have currently.
So the problem here arises when
Or in other words the key exists but the value being examined doesn't. When the value is then added the value that was already present there is over written. All help is course very much appreciated!
Thanks
Right now I have a hash with keys that have values but if I want to add another value to the hash key it overwrites the value already stored there. Is there anyway to make it so that I can store more than one value for a particular key? Below is the code that I have currently.
Code:
if($line2 =~ /^($line1)\s+CAAS.+\.([^.]+)\.([^.]+)/ )
{
$flag = 1;
my $keyExists = 0;
my $valueExists = 0;
while ( my ($key, $value) = each(%hash) )
{
if($key EQ $2)
{
print "key = $key two = $2\n";
$keyExists = 1;
if($value EQ $3)
{
print "value = $value three = $3\n";
$valueExists = 1;
}
}
}
print "keyExists $keyExists\n";
print "valueExists $valueExists\n";
if($keyExists == 1 && $valueExists == 0)
{
$hash{$2} = $3;
}
if($keyExists == 0 && $valueExists == 0)
{
$hash{$2} = $3;
}
$keyExists = 0;
$valueExists = 0;
print "keyExists $keyExists\n";
print "valueExists $valueExists\n";
#$hash{$2} = $3;
#print ("Found the string $line1 in the file $ARGV[1]\n");
#print ("Segment = $2 and COBOL Field Name = $3\n");
}
So the problem here arises when
Code:
if($keyExists == 1 && $valueExists == 0)
{
$hash{$2} = $3;
}
Or in other words the key exists but the value being examined doesn't. When the value is then added the value that was already present there is over written. All help is course very much appreciated!
Thanks