473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help Creating a Hash from a CSV file

numberwhun
3,509 Expert Mod 2GB
Ok, I have a ".csv" file that contains two lines (VERY LONG lines). Basically, the first line is the headers defining what each field in the second line is.

ie:
Expand|Select|Wrap|Line Numbers
  1. Name1,Name2,Name3,........
  2. Value1,Value2,Value3,.......
  3.  
Unfortunately, I am unable to provide any sample data as it is proprietary and customer confidential, but that is essentially the format of this file.

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
  1. se strict;
  2. use warnings;
  3.  
  4. ###### Array and Variable Declarations #####
  5. my @keysarray;
  6. my @valuesarray;
  7.  
  8. ##### Open Files For Reading #####
  9. open (K, "<keys.txt");
  10. open (V, "<values.txt");
  11.  
  12. my $totalelementsk = $#keysarray + 1;
  13. my $totalelementsv = $#valuesarray + 1;
  14. my %hash;
  15.  
  16. print $totalelementsk, "\n";
  17. print $totalelementsv, "\n";
  18.  
  19. if ($totalelementsk == $totalelementsv)
  20. {
  21.  for(my $i = 0; $i <= $totalelementsk ; $i++)
  22.  {
  23.     $hash{$keysarray[$i]} = $valuesarray[$i];
  24.  }
  25. }
  26.  
  27.  for my $key ( keys %hash ) {
  28.     my $value = $hash{$key};
  29.     print "$key => $value\n";
  30.  }
  31.  
Thanks in advance! I look forward to any assistance I can get.

Regards,

Jeff
Apr 25 '08 #1
5 1834
numberwhun
3,509 Expert Mod 2GB
Just an FYI, as I am trying to get an answer to this today, I am cross posting this with another board as well. If I get an answer that works, I will post it here.

Regards,

Jeff
Apr 25 '08 #2
KevinADC
4,059 Expert 2GB
see DIC
Apr 25 '08 #3
numberwhun
3,509 Expert Mod 2GB
see DIC
Well, I know what you mean, but that could SOOO be misconstrued on here. :-)
Apr 26 '08 #4
KevinADC
4,059 Expert 2GB
Hey, you're just a "New" DIC head, but I am a DIC head so please show me the proper DIC respect. And if other people have dirty minds, well, I wish they would share their thoughts with me! ;)
Apr 26 '08 #5
eWish
971 Expert 512MB
Although the opportunity is great, I am going to pass on this one. )

--Kevin
Apr 26 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check...
0
by: sipetar | last post by:
I have two file. file looks like this: first file: A#b1#c1 B#b2#c2 B#b3 C#b4#c4 D#b5#c5
6
by: \jason via DotNetMonster.com\ | last post by:
currently i am doing a personal website and keep on changing the aspect... finally the finall decision is to have a login page (requirement in asp.net, vb.net) and the login with security part of...
2
by: intrader | last post by:
I have a .NET interop assembly Hash.MD5Sum with two methods Identity and GetMD5Sum. I want to call the methods from ASP (JScript), The debugger tells me that object oMD5Sum has only one method...
5
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight...
1
by: John Wright | last post by:
I want to create a file hash on my exe files and store the hash signature in a database so I can retrieve the value to compare the file hash to ensure I have an untampered file. How can this be...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
2
by: muppetjones | last post by:
I have been receiving a "Floating point exception" from Perl after my program has run several iterations. I have not been able to pin point the location of the error, and I am clueless. Especially as...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.