in reply to Re^3: Stuck in my final step of code using array of arrays
in thread Stuck in my final step of code using array of arrays

With a change to kcott's solution, this could be achieved. Your code shows you don't understand the terniary operator something ? 'if true' : 'if false'. The 2 lines with your error are:

if($start=$i)

and

if($end=$i)

Note how I wrote the line for my $start and my $end.

my $start = $i == 0 ? $data[$i - 1][2] + 1 : 'none'; my $end = $i == $#data ? 'none' : $data[$i+1][1]-1;

You could rewrite your code to be:

if ($special{$data[$i][0]}) { if($i == 0) { $start = 'none'; } else { $start = $data[$i - 1][2] - 1; } if($i == $#data) { $end = 'none'; } else { $end = $data[$i + 1][1] - 1; } print join "\t" => $id, $data[$i][0], $start, $end; }
The solution would be:
#!/usr/bin/env perl -l use strict; use warnings; my %special = (PF03797 => 1); { local $/ = "//\n"; while (<DATA>) { my ($id) = /^ID:(\w+)/; my @data; while (/HIT:(\w+).*?SEQ_START:(\d+).*?(\d+)/g) { push @data, [ $1, $2, $3 ]; } @data = sort { $a->[2] <=> $b->[2] } @data; for my $i (0 .. $#data) { if ($special{$data[$i][0]}) { my $start = $i == 0 ? 'none' : $data[$i - 1][2] + 1; my $end = $i == $#data ? 'none' : $data[$i+1][1]-1; print join "\t" => $id, $data[$i][0], $start, $end; } } } } __DATA__ ID:A0AWZ5 HIT:PF12951 SEQ_START:120 SEQ_END:350 HIT:PF03797 SEQ_START:822 SEQ_END:1073 HIT:PF15789 SEQ_START:1515 SEQ_END:1547 HIT:PF00267 SEQ_START:1200 SEQ_END:1350 //
The output from my code was:

A0AWZ5  PF03797 351     1199

Hope this helps.