1

所以这是你能够帮助我的兴趣所在,程序是用 perl 编写的,我在 perl 中同时使用警告和严格,但我到了文本文件的末尾,然后我被卡住了最后的输出。

my $filename = 'trace-804-2.txt';
open(my $input, '<:encoding(UTF-8)', $filename)
or die "Couldn't open file '$filename' $!";

while ( <$input> )
{
    my ($row) = $_;
    chomp $row;
    ( $pkt_number[$i], $pkt_arrival[$i], $pkt_length[$i] ) = ( split(':',$row, 8)) [0,3,5];
    $pkt_number[$i] =~ s/\D//g;
    $pkt_length[$i] =~ s/\D//g;
    printf "Packet number %d ",$pkt_number[$i];
    printf "Arrival time %s ",$pkt_arrival[$i];
    printf "Length %d \n",$pkt_length[$i];
    $i++;
    $nr_of_pkts++;
}

这是我得到的输出

 Packet number 3 Arrival time 2662.050878565250 Length 256
 Packet number 4 Arrival time 2662.050981740750 Length 256
 Packet number 5 Arrival time 2662.051084976000 Length 256
 Packet number 6 Arrival time 2662.051188151750 Length 256
 Packet number 7 Arrival time 2662.051291327500 Length 256
 Packet number 8 Arrival time 2662.051394562750 Length 256
 Packet number 9 Arrival time 2662.051469485750 Length 256
 Packet number 10 Arrival time 2662.051497738250 Length 256
 Packet number 11 Arrival time 2662.051573317000 Length 256
 Packet number 12 Arrival time 2662.051600914000 Length 256
 Packet number 13 Arrival time 2662.051677088750 Length 256
 Packet number 15 Arrival time 2662.051704149250 Length 256
 Packet number 17 Arrival time 2662.051780920000 Length 256
 Packet number 18 Arrival time 2662.051807324750 Length 256
 Packet number 20 Arrival time 2662.051890115750 Length 256
 Packet number 21 Arrival time 2662.051910560000 Length 256
 Packet number 23 Arrival time 2662.051993887250 Length 256
 Packet number 24 Arrival time 2662.052013735750 Length 256
 Packet number 27 Arrival time 2662.052097718750 Length 256
 Packet number 29 Arrival time 2662.052116911250 Length 256

我知道它不会更进一步,因为在循环之后我有一个简单的 printf来标记程序已经过了那个阶段。

这是文本文件的内容:

[   3]:d10:mp10165:2662.050878565250:LINK(1266):CAPLEN( 256)
[   4]:d10:mp10165:2662.050981740750:LINK(1266):CAPLEN( 256)
[   5]:d10:mp10165:2662.051084976000:LINK(1266):CAPLEN( 256)
[   6]:d10:mp10165:2662.051188151750:LINK(1266):CAPLEN( 256)
[   7]:d10:mp10165:2662.051291327500:LINK(1266):CAPLEN( 256)
[   8]:d10:mp10165:2662.051394562750:LINK(1266):CAPLEN( 256)
[   9]:d00:mp10165:2662.051469485750:LINK(1266):CAPLEN( 256)
[  10]:d10:mp10165:2662.051497738250:LINK(1266):CAPLEN( 256)
[  11]:d00:mp10165:2662.051573317000:LINK(1266):CAPLEN( 256)
[  12]:d10:mp10165:2662.051600914000:LINK(1266):CAPLEN( 256)
[  13]:d00:mp10165:2662.051677088750:LINK(1266):CAPLEN( 256)
[  15]:d10:mp10165:2662.051704149250:LINK(1266):CAPLEN( 256)
[  17]:d00:mp10165:2662.051780920000:LINK(1266):CAPLEN( 256)
[  18]:d10:mp10165:2662.051807324750:LINK(1266):CAPLEN( 256)
[  20]:d00:mp10165:2662.051890115750:LINK(1266):CAPLEN( 256)
[  21]:d10:mp10165:2662.051910560000:LINK(1266):CAPLEN( 256)
[  23]:d00:mp10165:2662.051993887250:LINK(1266):CAPLEN( 256)
[  24]:d10:mp10165:2662.052013735750:LINK(1266):CAPLEN( 256)
[  27]:d00:mp10165:2662.052097718750:LINK(1266):CAPLEN( 256)
[  29]:d10:mp10165:2662.052116911250:LINK(1266):CAPLEN( 256)
4

1 回答 1

1

错误在 while 循环之外,在 printf 中缺少 /n (换行符):

}
close($filename);
sleep(1);
printf "step one";

我将其更改为:

}
close($filename);
sleep(1);
printf "step one \n";
于 2015-05-11T10:07:22.630 回答