The following code duplicates your new problem. I am using a memory file to simulate a disk file because I can show exactly what is on it. I am redirecting the output to STDOUT so we can see it. There is only one long line of output because you 'removed' the newline along with the comma.
use strict; use warnings; use autodie; my $simulation = \do{ 'field 01' . ','x79 . 'field 80,' . "\N{LF}" .'field 01' . ','x79 . 'field 80,' . "\N{LF}" }; *OUT = *STDOUT; my $OFFSET = -2; # second last chracter (the ',') in $line my $LENGTH = 2; # replace 2 charactrers (',' and \n) my $REPLACEMENT = ''; # replace specified characters with nothing open IN, '<', $simulation; while(<IN>) { my $line = $_; my $number = () = $line =~ /\,/gi; substr($line, $OFFSET, $LENGTH) = '' if ($number > 79); print OUT "$line"; } close OUT; close IN;

In this case, you should only delete one character, the last comma. (Change $LENGTH to 1) Why do you think you should delete two characters? Is my simulation wrong? How? It does assume that you are on a *NIX system. On other systems, perl's IO Layers hide the difference. Your loop should be identical.


In reply to Re^5: Trim Two Characters On Line by BillKSmith
in thread Trim Two Characters On Line by jalopez453

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.