in reply to Replacing Text At Specific Positions
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}
|
|---|