Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Maybe this is what you are taring to do.

#!/usr/bin/perl # use strict; use warnings; use Text::CSV_XS; my $csv = Text::CSV_XS->new(); #open (CSV, "<", $file_to_parse) or die "Could not open '$file' $!<br> +"; while (my $line = <DATA>) { chomp $line; if ($csv->parse($line)) { my @columns = $csv->fields(); $columns[0] =~ s/ //g; $columns[2] =~ s/ //g; if( ($columns[0]=~/^[0-9]+$/) && ($columns[2]=~/^[0-9]+$/) ) { print "Format ok\n"; foreach (@columns){print $_,"\t";}; print "\n"; }else{ print "Wrong Format\n"; print "First $columns[0] and tird $columns[2] have to be n +umeric\n"; } }else{ my $err = $csv->error_input; print "<br><b>$err Failed to parse line, please call for h +elp!</b><br>" if $err; } } __DATA__ 12345,John Dow, 123456 54321,ANDREW MALL, 8888882 987865,BOGGS BUNNY, 2234566 88777,CLARK KENT R, 888666 126677,CLARK KENT R, xx345778 112222,DAVOLIO DARK F, 3321777


perl "E:\perl_TK\" Process started >>> Format ok 12345 John Dow 123456 Format ok 54321 ANDREW MALL 8888882 Format ok 987865 BOGGS BUNNY 2234566 Format ok 88777 CLARK KENT R 888666 Wrong Format First 126677 and tird xx345778 have to be numeric Format ok 112222 DAVOLIO DARK F 3321777 <<< Process finished.

In reply to Re: CSV File Parsing by Generoso
in thread CSV File Parsing by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [james28909]: coffee <3

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2017-12-18 12:08 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (485 votes). Check out past polls.