【发布时间】:2021-01-16 04:18:57
【问题描述】:
这是我的文件的样子,
Time Send Receive Address
100 35 57 x9871
03 37 59 x9873
45 39 61 x9875
90 41 63 x9877
1234 43 65 x9879
45 76 89 x9768
我想按照时间递增的顺序排列数组,它应该看起来像,
Time Send Receive Address
03 37 59 x9873
45 76 89 x9768
45 39 61 x9875
90 41 63 x9877
100 35 57 x9871
1234 43 65 x9879
如果时间相同,它应该打印两个时间。到目前为止,我只能逐行读取文件。
#!usr/bin/perl
use warnings;
use strict;
my $logout_file = "ll.log";
my $temp1 = "temp1.log";
open(OUT, "+>>$logout_file") or die "Could not open file $logout_file: $!";
open (tmp,"<tempp1") or die "Couldn't open $fname";
while(my $aa= <tmp> ) {
@fields = split " ",$aa;
say OUT join("|",@fields));
}
close fh;
}
主要是我不知道我应该如何开始。我在谷歌上搜索了很多东西,但没有找到任何相关的东西。请任何人建议如何在不使用任何模块的情况下以标准方式(while 循环或 foreach 循环)进行操作。谢谢。
更新: 如果特定行中的某些列增加,(log2.txt)
Time Send Receive Address
100 35 57 x9871
03 37 59 x9873
45 39 61 x9875 x7890 x8976
90 41 63 x9877 x8765
1234 43 65 x9879
45 76 89 x9768
使用Data::Dumper 更新输出看起来像,
$VAR1 = {
'9' => [
'9 41 63 x9877'
],
'345678' => [
'345678 4554 5445 5656'
],
'3' => [
'3 37 59 x9873'
],
};
输出
Time Send Receive Address
03 37 59 x9873
03 37 59 x9873
45 39 61 x9875
45 76 89 x9768
45 39 61 x9875 x7890 x8976
45 76 89 x9768
90 41 63 x9877
90 41 63 x9877 x8765
100 35 57 x9871
100 35 57 x9871
1234 43 65 x9879
1234 43 65 x9879
【问题讨论】:
-
您能否详细说明
Time的含义?是一秒钟吗?例如。 100 秒、3 秒、45 秒..? -
@vkk05,是的,我们也可以在几秒钟内完成。