2

我目前正在尝试将语音标记添加到我从 CSV 文件编辑并当前存储在数组中的行的开头和结尾;我目前正在尝试使用 push 和 unshift。

use warnings;
use Text::CSV;
use Data::Dumper;
use constant debug => 0;
use Text::CSV;

print "Running CSV editor......\n";

#my $csv = Text::CSV->new({ sep_char => ',' });

my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";

my $fileextension = substr($file, -4);

#If the file is a CSV file then read in the file.
if ($fileextension =~ m/csv/i)
{   
print "Reading and formating: $ARGV[0] \n";

    open(my $data, '<', $file) or die "Could not open '$file' $!\n";

    my @fields;

    while (my $line = <$data>) 
    {       
    #Clears the white space at the end of the line.
    chomp $line;

    #Splits the line up and removes the <br />.
    my @lines = split qr{<br\s?/>}, $line;

    #Removes the control character.     
    shift (@lines); 
    print "\n";
    print $_,$/ for @lines;

    push (@lines, "\"");
    unshift (@lines, "\"");

当我尝试使用最后两行时,它不会在开头和结尾添加任何内容。

4

1 回答 1

1

你怎么知道引号没有被添加到数组中?您的语法是正确的,因此它们肯定可以正常工作。尝试这样的事情。

my $newStr = join $/, @lines;
print $newStr;

看看打印的内容,我敢打赌报价会在那里:)

于 2012-08-03T14:28:26.553 回答