I'm assuming you're using LWP::Simple
's get
function there. That doesn't return a list of lines of the response body, but a string containing the response body. So at first, you probably meant:
my $content = get($uri);
You could now go and read that line by line, passing each line to Text::CSV
s parse
method. That might appear to work in some cases, but as CSV files may contain embedded newlines, it won't be very reliable.
Instead, let Text::CSV
figure out what exactly is a line in the input by passing it a filehandle it can read from by itself. To do that, there's no need to save the file locally. You can just open a handle to a string:
open my $fh, '<', $content or die $!;
my $csv = Text::CSV->new({ sep_char => ',' });
while (my $row = $csv->getline($fh)) {
my @fields = @{ $row };
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…