This is an array of strings:
@array = ("1 2 3 4 5 6 7 8 10 14 15 20", "7 14 20", "21 22 23 24 40 50");
This is an array of arrays:
@array = ([1, 2, 3, 4, 5, 6, 7, 8, 10, 14, 15, 20], [7, 14, 20], [21, 22, 23, 24, 40, 50]);
This is a syntax error:
@array = (1 2 3 4 5 6 7 8 10 14 15 20, 7 14 20, 21 22 23 24 40 50);
It seems the second alternative is what you might be looking for. If yes, you should read perllol and perldsc.
| [reply] [d/l] [select] |
@array = (1 2 3 4 5 6 7 8 10 14 15 20, 7 14 20, 21 22 23 24 40 50);
This is not valid Perl code. Should that be three strings? Or three array references?
I want to combine the elements
How do you want to combine them? concatenate? Or sort numerically, and remove duplicates?
How do I merge two elements if all the elements of one element are present in other as in 0th and first element?
How are we supposed to know what your requirements are?
Also, what have you tried so far?
Please read How (Not) To Ask A Question.
| [reply] [d/l] |
- Your question is not clear to me, perhaps you can give an example of the output you expect from your program based upon the @array you showed.
- What have you tried already?
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] [d/l] |
I have an array like
Please post code that compiles (and put it in code tags), so we can know exactly what you have, without guessing.
| [reply] |
Nodes are written in html. Please use <br> tags to put some line breaks in so it's easier to read.
As to your problem (which I'm not completely sure I understand, but I think I have some idea what you're asking), if you want to combine multiple lists, remove duplicates, and sort the result, you're looking for a hash. If you make a hash key from each list element, the duplicates will automagically resolve themselves, and then you can sort keys %whatever_you_name_your_hash
to get the sorted result back as a list.
Edit: fixed and noted. | [reply] [d/l] [select] |
| [reply] |