-1
私はperlの新機能です。私は1つのcsvファイルの最初の列から文字列を取り込み、この単語の頻度を別のファイルで調べ、出力を3番目のファイルに出力したいとします。ここに私のコードです -1つのcsvファイルからの入力を取得し、perlの別のファイルの単語をカウントする方法
#!/usr/bin/perl
$inputfile = 'Input.txt';
$outputfile = 'Out.csv';
$file = 'File.csv';
open(INPUT, "<$inputfile") or die "Could not read from $inputfile, program halting.";
open(OUTPUT, ">$outputfile") or die "Could not open $outputfile, program halting.";
open(FILE, "<$file") or die "Could not read from $file, program halting";
@temp;
@token;
$count;
#skip first line of approved file
if(<FILE>)
{
(@temp) = split (/\,/);
}
$count = 0;
while(<FILE>)
{
@temp = split (/\,/);
print "First Column - @temp[0], ";
print "Count - @temp[1], ";
print "Priority - @temp[3], ";
$count = 0;
while(<INPUT>)
{
#read the fields in the current record into an array
@words = split(/\s+/);
foreach $word (@words)
{
$temp1 = @temp[0];
if($word == $temp1)
{
$count++;
}
}
}
print "$temp1 - Count - $count \n ";
print OUTPUT "$temp1,$count,@temp[3]";
print OUTPUT "\n";
}
close INPUT;
close OUTPUT;
close FILE;
print "Done, please check the output file.\n";
誰かを助けてください。
OKである必要があり、間違った使い方です。 。おめでとうございます。もう1つ質問があります - $ word = 12345と$ temp [1] = 1234を比較する方法をsubstrと比較する方法 – User312
正しい方法で比較すると、ファイルを読むときに新しい行を切り詰めるあなたの比較がうまくいくこと。 – Nagaraju
@ User312はその助けをしましたか? – Nagaraju