Syntactic Confectionery Delight PerlMonks

### Comment on

 Need Help??

Hi, I need something like this. I have file with numbers for example:
1 2 4 25 39 48
1 2 3 4 39
2 3 48
1 2 4 8 12
5 10 11 12 13
6
7 9
...
and I need to read first line and take all numbers in the 1st line (1,2,4,25,39,48) and save all the numbers in the 1,2,4,25,39 and 48 line.
So i will have (1,2,4,25,39,48,2,3,4,39,4,8,12), then i need remove duplicate items so i will have (1,2,3,4,8,12,25,39,48) and read others numbers in lines (1,2,3,4,8,12,25,39,48) and so on until i read all numbers in refers lines.
Then i need read remaining lines like (5,10,11,12,13) and (7,9) and do the same recursion with other lines. I write something like this:

while(my \$line = <LIST>) { chomp \$line; push @array, \$line; } for (my \$i=0; \$i<396; \$i++) { @new_array=(); @numbers=(); if(exists \$hash{\$i}) { print OUT1 "\$i\n"; } else { @new_array=split('\s', \$array[\$i]); foreach my \$el(@new_array) { chomp \$el; push @numbers, split('\s+', \$array[\$el-1]); } @numbers= uniq(@numbers); @numbers= sort @numbers; \$new[\$i]=@numbers; foreach my \$arg(@numbers) { print OUT "\$arg\n"; \$hash{\$arg}=\$arg; } } } sub uniq { return keys %{{ map { \$_ => 1 } @_ }}; }

but i dont know how to set some recursion to do it right. Any idea? Thank you. Daniel

In reply to I need help with some recursion by ragnarokPP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Please read these before you post! —
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?
• See Writeup Formatting Tips and other pages linked from there for more info.

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2017-11-25 00:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (354 votes). Check out past polls.

Notices?