[英]perl - printing text in excel spreadsheet
TEXT FILE 文本文件
malloc
calloc
free
.C source file .C源文件
MY CODE 我的密码
my $word_search_path = $ENV{'SCRIPT_PATH'}."\\word_search.txt";
open(FILE1, "< $word_search_path") or die $!;
chomp(my @words = <FILE1>);
close(FILE1);
my $input = $ARGV[0];
open(FILE, $input) or die $!; #source file
my @lines = <FILE>;
close(FILE);
my $temp_path = $ENV{'TEMPLOG'}."\\dynamic_alloc_log.csv";
open(FILE2, "> $temp_path") or die "couldn't open the file!";
foreach my $word(@words){
my $count = 0;
foreach(@lines){
if($_ =~ $word){
$count++;
}
}
print FILE2 $word. $count."\n";
}
close(FILE2);
OUTPUT I GET 我得到的输出
malloc0 #in 1st field
calloc1 #in 2nd field
free2
OUTPUT I NEED 我需要的输出
malloc 0 # malloc in one field , 0 in next field
calloc 1
free 2
it will be great if i can do without any Perl modules. 如果我可以不使用任何Perl模块,那就太好了。 One more thing TEXT FILE data are user defined.So its not fixed. 用户定义了TEXT FILE数据,因此它不是固定的。
Try changing your print statement to 尝试将打印声明更改为
print FILE2 "${word},${count}\n";
Or 要么
printf FILE2 "%s,%s\n", $word, $count;
Since you're already storing output to .csv
file, it should display fields properly in MS Excel
由于您已经将输出存储到.csv
文件,因此它应该在MS Excel
正确显示字段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.