Hi Everybody I’m quite new to perl modules and I am having real difficulties getting the right output for my file. I use strict and warnings as a matter of course.The first part is all fine and dandy taking an uplode file. The header file contains the order and seperation that I desire for my output, some of the values are from the input.csv file the others are just headings which I want to print to the output file for each line (which corresponds to an item), so input from the csv file plus the headings in the correct order filling the gaps as it were. Here is the code I’m trying to use
$filename = $csvuploaddir . $ARGV[1] or die "Usage: $0 filenamen";
$blistfile =$ARGV[1]; ##.csv
$blistfile =~ s/.csv/.txt/; ## changes .csv to .txt
$outfile = $csvuploaddir . $blistfile or die "Usage: $0 filenamen";
my @headers = qw(Item(", , ,title artist label , , media_condition https%3A//I,https%3A//S , , , comments PayPal%20Only%2C Money%20Orders/Cashiers%20Cheque%2C , 0"); and perhaps another );?
$csv_in = Text::CSV->new({binary => 1, auto_diag => 1});
$csv_out = Text::CSV->new ({
escape_char => '"',
quote_char => '"',
quote => undef,
sep_char => '[:]',
blank_is_undef => 0,
empty_is_undef => 0,
skip_empty_rows => 1,
});
open $in, '<:encoding(UTF-8)', "$filename";
open $out, '>:encoding(UTF-8)', "$outfile";
$csv_in->header($in);
$csv_out->say($out, [@headers]);
while ($row = $csv_in->getline_hr($in)) {
$csv_out->say($out, [$row->@{@headers}]);}
so this is the output I want
Item("[:][:][:]Title[:]Artist[:]Label[:][:][:]media_condition[:]https%3A//I[:]https%3A//S[:][:][:]Comments[:]PayPal%20Only%2C[:]Money%20Orders/Cashiers%20Cheque%2C[:]0");
and this is the output I’m getting.
title[artist[label[,[,[media_condition[https%3A//I,https%3A//S[,[,[,[comments[PayPal%20Only%2C[Money%20Orders/Cashiers%20Cheque%2C[
and with some records
Hard Way To Go[Nick Allen[Walas Records, Inc.[[[Mint minus[[[[[Lovely clean copy[[[
Show Me The Way[Harris Haith[Mastermind Mix Records[[[Very Good Plus[[[[[A bit tatty[[[
so ultimately the finishe file will be like this
Item("[:][:][:]Hard Way To Go[:]Nick Allen[:]Walas Records, Inc.[:][:][:]Mint minus[:]https%3A//I[:]https%3A//S[:][:][:]Lovely clean copy[:]PayPal%20Only%2C[:]Money%20Orders/Cashiers%20Cheque%2C[:]0");
Item("[:][:][:]Show Me The Way[:]Harris Haith[:]Mastermind Mix Records[:][:][:]Very Good Plus[:]https%3A//I[:]https%3A//S[:][:][:][A bit tatty[:]PayPal%20Only%2C[:]Money%20Orders/Cashiers%20Cheque%2C[:]0");
Dazz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1