By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,775 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,775 IT Pros & Developers. It's quick & easy.

Help with perl data structures and in-built functions.

P: 4
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
Share this Question
Share on Google+
6 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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

P: 4
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 2.5K+
P: 4,059
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

P: 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 2.5K+
P: 3,503
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 2.5K+
P: 4,059
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.