i know how remove key hash of array. given following file simple example, forth column third column in paired match , data in not sorted.
.... ns501570 www 3009824 3009848 .... ns501572 wad 3009848 3009898 ....
i collapse
ns501570 www 3009824 3009848 ns501572 wad 3009848 3009898
i wrote following code. selected third column key hash. therefore print values first entry , column 4 key of other one:
use warnings; use strict; $seq; while(<>){ chomp; @line = split; $seq->{"$line[2]" } = [@line]; } foreach $s (keys %{$seq} ) { ### @{ $seq->{$s}}[3] key second pair print @{ $seq->{$s}}[0],"\t",@{ $seq->{$s}}[1],"\t",@{ $seq->{$s}}[2],"\t",@{ $seq->{$s}}[3],"\t",@{ $seq->{@{ $seq->{$s}}[3]}}[0],"\t",@{ $seq->{@{ $seq->{$s}}[3]}}[1],"\t",@{ $seq->{@{ $seq->{$s}}[3]}}[2],"\t",@{ $seq->{@{ $seq->{$s}}[3]}}[3],"\n"; delete ${$seq}{@{ $seq->{$s}}[3]}; }
it works there small problem! no know how delete second key (in case 3009848 in second entry) without getting following error:
ns501570 www 3009824 3009848 ns501572 wad 3009848 3009898 use of uninitialized value in hash element @ find_mate2.pl line 22, <> line 2. use of uninitialized value in hash element @ find_mate2.pl line 22, <> line 2. use of uninitialized value in hash element @ find_mate2.pl line 22, <> line 2. use of uninitialized value in hash element @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in print @ find_mate2.pl line 22, <> line 2. use of uninitialized value in delete @ find_mate2.pl line 23, <> line 2.
it looks deleting 3009848 before 3009848 key iterated in foreach loop. can try simple next unless defined $seq->{$s};
since you've deleted $s==3009848 on interation 3009824. defined
checking never hurts...