2

現在、CSVファイルから編集し、現在配列に保存されている行の先頭と末尾にスピーチマークを追加しようとしています。私は現在、プッシュとアンシフトを使用しようとしています。

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, "\"");

最後の2行を使用しようとすると、開始と終了に何も追加されません。

4

1 に答える 1

1

引用符が配列に追加されていないことをどのように知っていますか?あなたの構文は正しいので、それらは間違いなく機能しています。このようなことを試してください。

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

そしてそれが何を印刷するかを見てください、私は引用符がそこにあるに違いありません:)

于 2012-08-03T14:28:26.553 に答える