Help with perl data structures and in-built functions.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • looza
    New Member
    • Jul 2008
    • 4

    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!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    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

    Comment

    • looza
      New Member
      • Jul 2008
      • 4

      #3
      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.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #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.

        Comment

        • looza
          New Member
          • Jul 2008
          • 4

          #5
          Originally posted by KevinADC
          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!

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by looza
            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

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              For what its worth, I was pretty sure it was school/class/course work too.

              Comment

              Working...