我正在解析一个文件 - 我做的第一件事是将前三个字段连接起来并将它们添加到每个记录中。然后我想擦洗任何冒号、单引号、双引号或反斜杠的数据。以下是我的做法,但有没有办法让我使用 $line 变量来做这件事会更有效?
# Read the lines one by one.
while($line = <$FH>) {
# split the fields, concatenate the first three fields,
# and add it to the beginning of each line in the file
chomp($line);
my @fields = split(/,/, $line);
unshift @fields, join '_', @fields[0..2];
# Scrub data of characters that cause scripting problems down the line.
$_ =~ s/:/ /g for @fields[0..39];
$_ =~ s/\'/ /g for @fields[0..39];
$_ =~ s/"/ /g for @fields[0..39];
$_ =~ s/\\/ /g for @fields[0..39];