推送和解除问题 - Perl

时间:2012-08-03 14:15:47

标签: perl

我目前正在尝试将语音标记添加到行的开头和结尾,我从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, "\"");

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

1 个答案:

答案 0 :(得分:1)

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

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

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