Hello everyone,

Scenario:

I have been given a comma delimited text file that I need to "clean-up" and convert into tab delimited. Easy enough if I use substitute to replace all commas with tabs, BUT in this file, there are company names that contain commas(nothin' is ever easy, is it?). For example the incoming text looks like:

client,ABC Company, jwilkens,jdoe,mdeart #this one is fine
client,Cornell,Thayil,Cameron & Sheppard, LLC, klivingston,amarison,pserton #this one is not
client,Doe,Smith & Randall, Inc, jwaters,pfloyd,jjoplin #this one is not

Now the one thing that is consistent (my example doesn't show this) is that the company names will always start at the 15th character from the left and end at the 25th character from the left. If a company name is shorter than 10 characters then spaces will be added to make it 10 characters.

My game plan is to

$foo = entire string (say 100+ characters); if {$foo contains a comma within the 15th thru 25th character from the + left then replace it with a "+"; #I can use any nonalpha character here }; replace all commas in $foo with "\t"; #replace all commas with tabs replace all "+" with commas; # replace all plus-signs with commas

My question is... How do I write the IF statement?
Also, someone wrote that this gets rid of empty spaces? If so, what does it substitute it with?

$foo =~ s/\s/\\g;
Thanks for your time.

In reply to Help with substitution - - 15 Characters from the left by La12

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.