Combinations using perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dandan
    New Member
    • Jun 2010
    • 8

    Combinations using perl

    Hello All,

    I'm sure your all sick of these questions.
    My problem is I want to combine files in all different ways without repeats.

    So say I have five files, file1, file2, file3, file4, file5. these are stored in an array.

    I then want to combine like so (file1, file2), (file1, file3) and so on
    then (file1, file2, file3) (file1, file2, file4) ... but then I will need to do (file1, file3, file4)...
    then add another file to combine (file1, file2, file3, file4) untill all combinations without repeating the same file in a combination.

    Can anyone give me some advise.

    I think I need an array of files, then a copy of this array to Combine the files then an array of the combinations. So I would iterate with a for loop through the @files while iterating through the @files2comb, then storing the combinations in @combines. But then I'm not too sure how to go about implenting it.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Ok, so what have you tried thus far to do this? We would really like to see the code that you have tried so far, to do this and also tell us what you are seeing, what is happening, etc. Any errors are good to.


    Regards,

    Jeff

    Comment

    • dandan
      New Member
      • Jun 2010
      • 8

      #3
      Thanks for replying.
      This is my first time using Perl, I haven't implemented it yet I am working on the algorithm, I am jotting ideas down on paper, then going through and calculating them in my head and realising that it is not correct. I have now been looking at the math behind Permutations and Combinations. but then I don't want to generate 1,2,3 and 2,1,3 ... Can you reccomend anything for me to read to understand how to do this. I will look through my notes and put up the directions I have been working in.
      Thanks Again

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        It sounds like you are delving into the algorithms arena of Perl. If that is the case, then this might prove good reading for you.

        Post your Perl code so we can see what you have been trying and we will help you from there.

        Regards,

        Jeff

        Comment

        • dandan
          New Member
          • Jun 2010
          • 8

          #5
          Originally posted by numberwhun
          It sounds like you are delving into the algorithms arena of Perl. If that is the case, then this might prove good reading for you.

          Post your Perl code so we can see what you have been trying and we will help you from there.

          Regards,

          Jeff
          Thank you
          I have decided to use the permutations and skip any repeats, I think I have it figured out.
          Setting up an extra array to identify the spaces to use but still generating the combinations using all the files.

          However I have another questions.
          Could you give me any advice on how to run a script and pass arguments to that script from within another?

          I have looked at require and $ARGV but I need the script to execute the arguments passed and without ending the orginal program.

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Too bad you are averse to showing your code, we could have provided you some good guidance.

            As for your new question, look at the system() function or using backtics.

            Regards,

            Jeff

            Comment

            • dandan
              New Member
              • Jun 2010
              • 8

              #7
              Originally posted by numberwhun
              Too bad you are averse to showing your code, we could have provided you some good guidance.

              As for your new question, look at the system() function or using backtics.

              Regards,

              Jeff
              Thank You again Jeff.

              Going over this for ages with a stupid mistake missing out something.

              Sorry I did not put up any code I am doing work for someone and not sure if I am able to post it.

              But thanks again for your help.

              Comment

              Working...