私は2つのテーブルを持っています。特定の条件が満たされた場合に、あるファイルから別のファイルに値をコピーしたい。これは、すべてがどのように見えるかです
表1
C1 C2 C3
1 a b
3 e f
表 2
C1 C2 ... ... C7 C8 ...
1
2
3
表 2 は次のようになります。
C1 C2 ... ... C7 C8 ...
1 x=b
2
3 x=f
したがって、C1 (テーブル 1) と C2 (テーブル 2) の値が同じ場合、テーブル 1 の C3 の値をテーブル 2 の列 C8 に入れる必要があります。C8 の新しい値はすべて「x=」で始まり、その後に続く必要があります。表1の対応する値によって
これは、これまでデータを開くために使用しているスクリプトです
my $data1 = $ARGV[0];
my $data2 = $ARGV[1];
unless ($data1) {
print "Enter filename:\n";
$data1 = <STDIN>;
chomp $data1;}
open(DATA1,'<',$data1) or die "Could not open file $filename $!";
unless ($data2) {
print "Enter filename:\n";
$data2 = <STDIN>;
chomp $data2;}
open(DATA2,'<',$data2) or die "Could not open file $filename $!";
while (<DATA1>) {
my @columns = split /\s+/;
next if /^\s*C/;
# I'm doing some transformations here so that my input DATA1 has the format of table 1 in my example
}
foreach $c1(sort {$a<=>$b} keys %info ) {
print $c1, "\t",
join(',',@{$info{$c1}->{variant}}), "\t",
join(',',@{$info{$c1}->{frequency}}), "\n";
# so $c1 is actually how table 1 in my example looks like
}
my %hash;
while($c1){
my @columns = split;
$hash{$columns[0]} = [$columns[2]];
}
while (<DATA2>) {
my @columns = split;
$columns[7] = @{ $hash{ $columns[0] } }[2] if exists $hash{ $columns[0] };
print "\t", join (@columns), "\n";
}
これは、@choroba が提供するソリューションを使用したスクリプトです。ただし、画面に何も出力されないため、何かが間違っているに違いありません。
また、値をコピーするときにステートメント「x =」を追加するにはどうすればよいですか?