467,179 Members | 1,298 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

Help with perl data structures and in-built functions.

I have never used perl before, and I was recommended to use this to write a script for this:

I have a file that has 2 columns like this:
A B
10 33
8 20
30 90

If B falls in a certain range, say 15 < B < 30, I need to store the corresponding value of A, 8 in this case, in some structure (hashtable?)

I have another file that looks like this
C D
34 X
40 Z
8 Y

If the value in C matches the one in our structure, I need to store the corresponding value of D someplace (an array?). In this case, since 8 is present in our structure, I store the value Y.

Am I on the right track or is there a smarter way to do this in perl?

Thanks!
Jul 9 '08 #1
  • viewed: 984
Share:
6 Replies
numberwhun
Expert Mod 2GB
This sounds like a homework question and since this is a learning forum, our policy strictly prohibits the posting of homework for answers.

So, that said, why not post the code that you have tried and we will help you get it working.

Regards,

Jeff
Jul 9 '08 #2
1. Its not a homework question
2. I DO NOT need the code, I just need to know if Perl has any other structures/functions I can use to make it more efficient, and I needed to know that BEFORE I started writing the code.

Anyway, I will just use whatever my limited knowledge of Perl allows and post if I have any problems.
Jul 10 '08 #3
KevinADC
Expert 2GB
Keep in mind that the keys of a hash are unique, there can be no two keys that are the same. From what you have described perl can easily handle this task, how you do it though depends on what the purpose of the program will be. But I believe you are thinking along the correct lines. It will help though if you do get some code started, from there we can help you better.
Jul 10 '08 #4
Keep in mind that the keys of a hash are unique, there can be no two keys that are the same. From what you have described perl can easily handle this task, how you do it though depends on what the purpose of the program will be. But I believe you are thinking along the correct lines. It will help though if you do get some code started, from there we can help you better.
Thanks for your help Kevin!
Jul 10 '08 #5
numberwhun
Expert Mod 2GB
1. Its not a homework question
2. I DO NOT need the code, I just need to know if Perl has any other structures/functions I can use to make it more efficient, and I needed to know that BEFORE I started writing the code.

Anyway, I will just use whatever my limited knowledge of Perl allows and post if I have any problems.
Please know that I was stating the policy because I have to. If you read your question, it sounds like it could be homework. There were no accusations, just hints at possibilities. If it is not homework, that's fine, just say so.

I agree with Kevin that your thinking was along the correct lines though. :)

Regards,

Jeff
Jul 10 '08 #6
KevinADC
Expert 2GB
For what its worth, I was pretty sure it was school/class/course work too.
Jul 10 '08 #7

Post your reply

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

Similar topics

2 posts views Thread by Sridhar R | last post: by
2 posts views Thread by JS | last post: by
1 post views Thread by kroty | last post: by
2 posts views Thread by shahoo | last post: by
4 posts views Thread by Dave | last post: by
1 post views Thread by saikiranbiet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.