473,748 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Creating a Hash from a CSV file

numberwhun
3,509 Recognized Expert Moderator Specialist
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,,,,,,,val ue,,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 1856
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
see DIC
Apr 25 '08 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
see DIC
Well, I know what you mean, but that could SOOO be misconstrued on here. :-)
Apr 26 '08 #4
KevinADC
4,059 Recognized Expert Specialist
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 Recognized Expert Contributor
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
4701
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 the referential integrity box. What gives? Continuing on with that line of thinking, I understand what do the relationships do for you in a database, but what do they do physically to the tables? Thanks,
0
1091
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
2793
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 capturing user computer user name i have done... my problem is .... i need the unregistered user to log in to my site and from there there will be a link for them to key in their short information in a textbox and a html email will be sent to...
2
1868
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 (ToString()). How do I get the Identity and GetMD5Sum methods to be accessible? I include the entire .net assembley followed by a snippet of the ASP code. /////The code of the .NET assembly is: using System;
5
2656
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 appreciated in advance. I am trying to reduce duplicate files in storage at home - I have a large number files (e.g. MP3s) which have been stored on disk multiple times under different names or on different paths. The using applications will...
1
8124
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 done in VB.NET 2005 john
4
2201
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 implement all three techniques as programs. In these programs, as well as solving the problem, you will also measure how long the program takes to run. The programs are worth 80% of the total mark. The final 20% of the marks are awarded for a...
6
2126
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 implement all three techniques as programs. In these programs, as well as solving the problem, you will also measure how long the program takes to run. The programs are worth 80% of the total mark. The final 20% of the marks are awarded for a...
2
2574
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 I can't seem to find exactly what this exception means. 1) What is a floating point exception? 2) What causes it? 3) Is there any way to fix it? I have included my code below, but as there is quite a bit any suggestion of how to handle...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.