ie:
Expand|Select|Wrap|Line Numbers
- Name1,Name2,Name3,........
- Value1,Value2,Value3,.......
Now, the first line of comma separated values, being the headers, contains 408 values. The second line contains the same number of comma separated fields, but some are empty. (FYI, empty fields would look like: value,,,,,,,value,,value).
Hopefully this is making sense. My question is this, I want to create a hash and print out these values (or lack there of) side by side so I can correlate what is missing with what is there. The reason for wanting this is because looking at it in this format is giving me a really bad headache.
So, I had used split to split the first line into an array and then did the same with the second line. After that, I tried putting them into a hash, but because of the missing values in the second line, some necessary elements did not get created because they are null. Thus, the comparison to see if the two element counts was off and the hash didn't get created.
Does anyone have any idea how I can get this to work and enter a null value into the array where there is a null value, thus enabling this printout to work properly? My code is below.
Expand|Select|Wrap|Line Numbers
- se strict;
- use warnings;
- ###### Array and Variable Declarations #####
- my @keysarray;
- my @valuesarray;
- ##### Open Files For Reading #####
- open (K, "<keys.txt");
- open (V, "<values.txt");
- my $totalelementsk = $#keysarray + 1;
- my $totalelementsv = $#valuesarray + 1;
- my %hash;
- print $totalelementsk, "\n";
- print $totalelementsv, "\n";
- if ($totalelementsk == $totalelementsv)
- {
- for(my $i = 0; $i <= $totalelementsk ; $i++)
- {
- $hash{$keysarray[$i]} = $valuesarray[$i];
- }
- }
- for my $key ( keys %hash ) {
- my $value = $hash{$key};
- print "$key => $value\n";
- }
Regards,
Jeff