Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Dear monks,
it seems that the script I've been using has a problem with the line endings when used on a Mac. I've tried
eol => '\012' eol => '\015' eol => '\l' eol => '\r'
But neither of these did work. Did I forget an alternative?
#!/usr/bin/perl -w use strict; use diagnostics; use Text::CSV; my $qfn_in = 'data.csv'; open( my $fh_in, '<', $qfn_in ) or die("Can't open file \"$qfn_in\": $!\n"); my $fh_out = \*STDOUT; my $csv_in = Text::CSV_XS->new( { sep_char => ',', binary => 1, eol => '\015' } ) +; my $csv_out = Text::CSV_XS->new( { sep_char => "\t", eol => $/ } ); while ( my $row = $csv_in->getline($fh_in) ) { $csv_out->print( $fh_out, [ @$row[ 2, 3, 0, 4 ], ] ); }


As an alternative I looked at using *Text::ParseWords* (see below) but just couldn't get more then data of just the first line produced. Maybe someone could help me with that.
Thanks in advance,
Gert
#!/usr/bin/perl -w use strict; use diagnostics; use Text::ParseWords; my $mydata = "data.csv"; open( FILE, "<$mydata" ) or die("Couldn't open CSV file $mydata:$!\\n"); my $line; my @fields; while ( $line = <FILE> ) { @fields = &quotewords( ',', 0, $line ) or ( warn "a problem on line $.:$_" ); # Set variable values based on the array values. my $id = $fields[0]; my $brand = $fields[1]; my $dbt = $fields[2]; my $cdt = $fields[3]; my $color = $fields[4]; my $number = $fields[5]; } exit;

In reply to line ending problem Text::CSV alternative Text::ParseWords? by GertMT

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found