user6037276 user6037276 - 6 months ago 14
Perl Question

what does the $F[2]..$F[3] mean?

my input file:

1 chr19 58858171 58874214 A1BG ENSG00000121410
2 chr12 9220303 9268558 A2M ENSG00000175899
3 chr12 9381128 9386803 A2MP1 ENSG00000256069
9 chr8 18027970 18081198 NAT1 ENSG00000171428
10 chr8 18248754 18258723 NAT2 ENSG00000156006
12 chr14 95058394 95090390 ENSG00000273259
13 chr3 151531860 151546276 AADAC ENSG00000114771
14 chr2 219128851 219134893 AAMP ENSG00000127837
15 chr17 74449432 74466199 AANAT ENSG00000129673
16 chr16 70286296 70323412 AARS ENSG00000090861


my Perl script:

open FH, $ARGV[0];

while (<FH>) {

@F = split;
$F[1] =~ /chr(\w+)/;

$chr = $1;

foreach ( $F[2] .. $F[3] ) {
$hash{"$chr\t$_"} = $F[4];
}
}

close FH;

foreach $key ( keys %hash ) {
print "$hash{$key}\n";
}


I have two question about the script.


  1. Why infinite loop appears to the script?

  2. Could you please tell me what does the
    $F[2] .. $F[3]
    mean?


Answer

Why infinite loop appears to the script?

There's no infinite loop. For the input provided, it creates a hash with 239,517 elements, then dumps the hash. The output starts appearing almost immediately.

Could you please tell me what does the $F[2]..$F[3] mean?

In list context, if $F[2] and $F[3] are numbers, it returns a sequence of numbers from $F[2] to $F[3] inclusive.

$ perl -E'for my $i (10..15) { say $i }'
10
11
12
13
14
15
Comments