Hi Monks, I have a script that converts an xlsx spreadsheet into a comma seperated csv format and pushes to an array. The next step deletes any dupliacte lines.

If i print to screen it looks fine and has done what i expect. But when i use print to show me where the newlines are it shows as one line.

How do i get a newline at the end of each row ie the Pass column.
# test.pl #!/usr/bin/perl use strict; use warnings; use Spreadsheet::BasicRead; open( STDERR, ">&STDOUT" ); my $xlsx_INFILE =("C:\\Temp\\Test.xlsx"),, 1; #Set-up Files my @csvtemp; my $ss = new Spreadsheet::BasicRead($xlsx_INFILE) or die " oops \n" +; # convert $INFILE to a csv file my $name = ''; my $row = 0; while ( my $data = $ss->getNextRow() ) { $row++; $name = join( ',', @$data ); push @csvtemp, $name . "\n" if ( $name ne "" ); } my @csvsort; my %seen; # remove any duplicates lines foreach (@csvtemp){ push @csvsort, $_ if !$seen{$_}++ ; } print("'@csvtemp'");
__DATA__ Name job gender Data of Sick Reg Pass marshall plumber Male ten Jones baker Male none Smith cleaner Male none 387622 Tucker cleaner Female none 387628 Butcher blacksmith Male none 386626 Patel Builder Male none Black plumber Male Two Cooper baker Female none Jess cleaner Male none Booker cleaner Male Six 387626 Patel Builder Male none Black plumber Male Two Cooper baker Female none Jess cleaner Male none Booker cleaner Male Six 387626
expected data
'Name,job,gender,Data of Sick,Reg,Pass' 'marshall,plumber,Male,ten,,' 'Jones,baker,Male,none,,' 'Smith,cleaner,Male,none,387622,' 'Tucker,cleaner,Female,none,387628,' 'Butcher,blacksmith,Male,none,386626,' 'Patel,Builder,Male,none,,' 'Black,plumber,Male,Two,,' 'Cooper,baker,Female,none,,' 'Jess,cleaner,Male,none,,' 'Booker,cleaner,Male,Six,387626,'

In reply to Perl to Add newline at the end of each row of comma seperated strings in an array ? by john.tm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.