You didn't mention whether this program actually does what you want it to do, or does something else instead. Also, while it's clear you want to replace commas with vertical bars, it's not really clear what you're trying to do with the last field on each line of input.

The replacement of commas with vertical bars can be done much more easily:

while (<IN>) { tr/,/|/; print OUT; }
(you can look up the "tr///" operator in the perlop manpage) Note that you are already assuming that all commas in each line are field delimiters (i.e. there are no commas that are included within quoted fields, or that are escaped in some way, and should not be interpreted as delimiters) -- also, you are taking for granted that every line will contain the same number of commas and fields. If you're really confident that your input data are consistent with these assumptions, then there's no problem. But be aware that many applications do not have this luxury.

As for this part of your code:

$string1 = $var7; substr($string1, 24) = "H:\"; $string2 = substr($string1,25,2); $string3 = substr($string1,-13); $finstring = $string1.$string2.$string3;
This makes assumptions about the length of the last field of on each input line. It also appears to always set $string2 to ":\" -- is that your intention? (If so, your code is just obfuscated.)

No way for anyone here to know what $string3 would be, without seeing some of the data. There is almost certainly a better/easier way to accomplish what you're trying to do, but you'll need to post a reply with more info about the data.


In reply to Re: Open file & Strip comma delimiter by graff
in thread Open file & Strip comma delimiter by skyler

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.