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

Combinations using perl

P: 8
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.
Jun 16 '10 #1
Share this Question
Share on Google+
6 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Jun 16 '10 #2

P: 8
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
Jun 16 '10 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
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
Jun 16 '10 #4

P: 8
@numberwhun
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.
Jun 23 '10 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
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
Jun 23 '10 #6

P: 8
@numberwhun
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.
Jun 25 '10 #7

Post your reply

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