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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |