Hello all:

So as not to further distract the cb from its discussion of Zappa's life's work, I bring this question here.

I am working on a script to clean and import a large csv data file into a postgres backend. My duplicate checks are failing to prevent fatal errors related to unique data constraints applied to some tables. As I drill into this issue, what I'm finding is that my regex's are not working as I thought they would.

#!/usr/bin/perl -w use strict; use warnings; open ('CSV','<',$file); while (<CSV>){ $counter++; @fields = split ",",$_; my($ndx); foreach $ndx (0 .. (0 + @fields -1)){ $fields[$ndx] =~ s/\s*$//g; $fields[$ndx] =~ s/'/\\'/g; $fields[$ndx] =~ s/"//g; if($ndx == 32){ print STDERR "For field $ndx, the value is now: |$fields[$ndx]| +\n"; my @chars = split(//, $fields[$ndx]); foreach my $chr (@chars) { print STDERR '|' . ord($chr) . '|,'; } print STDERR "\n"; } } close('CSV');
This is yielding debug output which looks like this:

For field 32, the value is now: |096 | |48|,|57|,|54|,|32|,|32|,
Field #32 is only a representative sample. This issue is showing up on several fields actually.

Can anyone please explain why this is happening for me, please? And more important what I can do about it?

Thanks,

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to Baffled by data cleaning regex issue by hesco

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.