473,399 Members | 3,832 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,399 software developers and data experts.

Parsing a file into a hash

I have got a file containing info abt node id and labels, which looks like this

Expand|Select|Wrap|Line Numbers
  1. -645    _1__46__1__46__1__46__145__45__RXN
  2. -435    _3__45__OXOACYL__45__ACP__45__REDUCT__45__RXN
  3. -1084    RXN__45__4262
  4. -565    RXN__45__4264
  5. -740    RXN__45__710
  6. -1290    RXN__45__7698
  7. -1017    LIPOXYGENASE__45__RXN
  8. -198    RXN__45__1321
  9. -1151    RXN__45__4121
  10. -55    GIBBERELLIN__45__3__45__BETA__45__DIOXYGENASE__45__RXN
  11. -1276    NARINGENIN__45__3__45__DIOXYGENASE__45__RXN
  12. -653    RXN__45__113
  13. -455    RXN__45__114
  14.  
i have to read this file into a hash, for which i converted it first into an array, and then to hash, using a program like this

Expand|Select|Wrap|Line Numbers
  1. open (NODES, "node.txt") || die "File not found\n";
  2. @nodearray=<NODES>;
  3. %nodehash=@nodearray;
  4.  
now i have got to take labels as input from the user, and return the node id. I have been trying the following code

Expand|Select|Wrap|Line Numbers
  1. # usr/bin/perl -w
  2.  
  3. $start_node = 'AT1G51570';
  4. $end_node = 'AT5G1110';
  5.  
  6. open (NODES, "node.txt") || die "File not found\n";
  7. @nodearray=<NODES>;
  8. %nodehash=@nodearray;
  9.  
  10. while (($node_id,$label) = each %nodehash) {
  11.     if ($nodehash{$label} = $start_node) {
  12.         print $nodehash{$node_id};
  13.     }
  14. }
  15.  
but nothing is working out. Please help me out on it. I am new to programming, and my deadline is just arriving. Please suggest something....
Jul 24 '07 #1
2 1727
KevinADC
4,059 Expert 2GB
Please suggest something...
ask a question that we can understand so we can attempt to answer it.
Jul 26 '07 #2
numberwhun
3,509 Expert Mod 2GB
but nothing is working out. Please help me out on it. I am new to programming, and my deadline is just arriving. Please suggest something....
Just taking a quick look, I am going to guess that this is not the entire data file since the $start_node value doesn't exist anywhere in there.

I must say that I agree with Kevin and need to clarify better what exactly you are asking and looking for. You say that the two fields in the file are node_id and label, in that order. Then the user enters a label, you are supposed to match it against the file and if a match occours, then print the node_id. From what I can see though, that is NOT what you are doing. You are comparing what the user would enter to a fixed value($start_node), if the user were even able to enter a value. Your script doesn't allow for the user input that you are mentioning.

I think that you really need to clean up this program and try to get it working. Heck, pick up a copy of Learning Perl as it will truely help you with the language and writing Perl code. If you still have problems after trying to meet your requirements, then be sure to repost, but please word the question better so we are able to assist you.

Regards,

Jeff
Jul 26 '07 #3

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

Similar topics

5
by: _DS | last post by:
I'm currently using a switch with about 50 case statements in a stretch of code that's parsing XML attributes. Each case is a string. I'm told that switch statements will actually use hash tables...
1
by: sp | last post by:
i have an xml file (an rss file) <?xml version="1.0" ?> <rss version="2.0"> <channel> <title>CodeGuru.com</title> <link>http://www.codeguru.com/</link> <description>The number one developer...
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...
14
by: mens libertina | last post by:
Disclaimer: In addition to reading the skimpy entries at php.net, I've searched this group and alt.php to no avail. Basically, I'm trying to use a template to send email reminders, but I can't...
3
by: Iris83 | last post by:
Hi, Im a new to perl and i hope there are people here that can help me! I have a realy large file like this. 1,12,T, 2,13,B, 3,14,T, 4,15,B, I want to use the 2nd and 3th column and put it...
2
by: amittewarii | last post by:
Hello Everybody , I need help in parsing the given file , ################################################################# <sample_cfg : 00FF_F000> #f_name ...
4
by: subeen | last post by:
Hi, I am trying to parse a rss similar to the one found here (in example) http://www.feedforall.com/mediarss.htm <!-- Snipped for Brevity --> <item> <title>FeedForAll's Show Tunes and...
6
by: whiteideal | last post by:
hay, guys, i just want to create a svg file according to my data, but i don't know whether there is some opensouce lib to do such things. Can you tell me about it? Thanks.
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.