<?xml version="1.0" encoding="windows-1252"?>
<node id="1007887" title="I need help with some recursion" created="2012-12-08 05:44:37" updated="2012-12-08 05:44:37">
<type id="115">
perlquestion</type>
<author id="1007883">
ragnarokPP</author>
<data>
<field name="doctext">
&lt;p&gt;Hi,
I need something like this. I have file with numbers for example:
&lt;br&gt;1 2 4 25 39 48
&lt;br&gt;1 2 3 4 39
&lt;br&gt;2 3 48
&lt;br&gt;1 2 4 8 12
&lt;br&gt;5 10 11 12 13
&lt;br&gt;6
&lt;br&gt;7 9
&lt;br&gt;...

&lt;br&gt;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.&lt;br&gt; 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.&lt;br&gt; 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:&lt;/p&gt;

&lt;code&gt;
while(my $line = &lt;LIST&gt;)
{
	chomp $line;
	push @array, $line;
}

for (my $i=0; $i&lt;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 { $_ =&gt; 1 } @_ }};
}
&lt;/code&gt;
&lt;p&gt;
but i dont know how to set some recursion to do it right. Any idea? Thank you. 
Daniel
&lt;/p&gt;</field>
</data>
</node>
