小编Rob*_*len的帖子

使用Text :: CSV_XS拆分功能

我试图解析日志文件并将其转换为.csv文件.我在分割功能方面遇到了麻烦.例如,我在日志文件中有以下内容:21a94551,00:00:59.643;错误; .当我尝试拆分逗号(,)和半冒号(;)时,我从输出csv文件中的时间戳中丢失.643.我想保持时间(00:00:59.643)完好无损.我在日志文件中有多行(都有不同的数字),所以这些值不明确.

当我在分割功能之后使用打印功能时,值将输出到屏幕确定,但在CSV文件中

我是Perl的新手.有人可以解释一下我做错了什么吗?我认为问题可能在于如何处理字符串?

use strict;
use Cwd;
use Excel::Writer::XLSX;
use Text::CSV_XS;
use Spreadsheet::Read;

my $dirname = getcwd;               # Set the directory to current working directory.
opendir (DIR, $dirname) || die;     # Open the current directory
my @FileNameList = readdir(DIR);    # Load the names of files in to an array

foreach (@FileNameList)             #Read each of the file names
{
    my $FileName = $_;
    my $Output;

    if ($FileName =~ m/iusp_\d+.log/)
        {
        print ("\n". $FileName." \n Correct Log File …
Run Code Online (Sandbox Code Playgroud)

regex csv perl

1
推荐指数
1
解决办法
149
查看次数

标签 统计

csv ×1

perl ×1

regex ×1