【发布时间】:2019-01-08 10:39:37
【问题描述】:
我有一个 perl 脚本,它逐行读取文本文件并将该行分成 4 个不同的列(用破折号显示,在代码中称为 $cols[0-3];重要部分用粗体表示)。对于第 0 列小数点之前的每个不同值,它应该随机生成一个十六进制颜色。
本质上,我需要比较当前行中的第 X 列是否与上一行匹配。
A----last_column----221----18
A----last_column----221----76
A----last_column----221----42
B----last_column----335----18
C----last_column----467----83
到目前为止,我正在为每一行随机生成一个新的#random_hex_color,但所需的输出如下:
221.18--------#EB23AE1--------@$some/random/path/A.txt -------last_column
221.76-------#EB23AE1--------@$some/random/path/A.txt -------last_column
221.42--------#EB23AE1--------@$some/random/path/A.txt -------last_column
335.18--------#AC16D6E-------@$some/random/path/B.txt -------last_column
467.83--------#FD89A1C-------@$some/random/path/C.txt -------last_column
[输入文件和所需输出的图像][1]
my @cols;
my $row;
my $color = color_gen();
my $path = "\t@\some_random_path/";
my $newvar = dir_contents();
my @array = ($color, $path, $newvar);
my %hash;
while ($row = <$fh>){
next if $row =~ /^(#|\s|\t)/; #skip lines beginning with comments and spaces
@cols = split(" ", $row);
%hash = (
"$cols[2]" => ["$color", "$path", "$newvar"]
);
say Dumper (\%hash);
print("$cols[2].$cols[3]\t#");
print(color_gen());
printf("%-65s", $path.dir_contents());
print("\t\t$cols[0]_"."$cols[1]"." 1 1\n");
}
【问题讨论】:
-
欢迎来到 Stack Overflow,Cori!如果您有时间,请访问我们的help center 和tour。