Reformatting your code a bit reveals
while (<INFILE>) { my $line = $_; chomp($line); # -----A line starting with a '2' is a header and is l +eft unchanged if ( $line !~ m/^2/ ) { # -----Locate postions 100 and 149 $juris1 = substr( $line, 99, 1 ); $juris2 = substr( $line, 148, 1 ); $juris1 = "9"; $juris2 = "Z"; # -----Generate the output string----- $output_line = substr( $line, 0, 98 ) . $juris1 . substr( $line, 100, 48 ) . $juris2 . substr( $line, 149, 61 ) . "\n"; print OUTPUT $output_line; last; } }

that there's no 'else' for your 'if'. What are you supposed to do when you hit /^2/, again? if you've found the /^2/ line, just stream through the rest of the file?

while (<INFILE>) { my $line = $_; chomp($line); # -----A line starting with a '2' is a header and is l +eft unchanged if ( $line !~ m/^2/ ) { # -----Locate postions 100 and 149 $juris1 = substr( $line, 99, 1 ); $juris2 = substr( $line, 148, 1 ); $juris1 = "9"; $juris2 = "Z"; # -----Generate the output string----- $output_line = substr( $line, 0, 98 ) . $juris1 . substr( $line, 100, 48 ) . $juris2 . substr( $line, 149, 61 ) . "\n"; print OUTPUT $output_line; # last; # <-- this last exits the input loop, +no more lines read. # Is that really what you want to do? # exit the loop after the first non - +/^2/ - line? } else { print OUTPUT while <INFILE>; } }

But your negated 'if' condition and the comment above it confuses me a bit. Shouldn't that be

# ----- Do as long as line doesn't start with '2'

or such?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Replacing Text At Specific Positions by shmem
in thread Replacing Text At Specific Positions by sheasbys

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.