in reply to Replacing Text At Specific Positions

$output_line = substr( $line, 0, 98 ) . $juris1 . substr( $line, 100, 48 ) . $juris2 . substr( $line, 149, 61 ) . "\n";

can be made a bit more readable:

$output_line = "$line\n"; substr($output_line, 99, 1) = $juris1; substr($output_line, 148, 1) = $juris2;

or

$output_line = "$line\n"; substr($output_line, 99, 1, $juris1); substr($output_line, 148, 1, $juris2);

Otherwise, it looks like the only problem you have is that you're not printing out the lines starting with "2", and you end the loop prematurly using last.

while (<INFILE>) { my $line = $_; if ( $line !~ m/^2/ ) { substr($line, 99, 1, "9"); substr($line, 148, 1, "Z"); } print OUTPUT $line; }

Are you having any other problems?

Replies are listed 'Best First'.
Re^2: Replacing Text At Specific Positions
by ikegami (Patriarch) on Jun 05, 2007 at 16:01 UTC
    Or if you're trying to preserve all the lines starting with the line starting with "2", then:
    my $found_2; while (<INFILE>) { my $line = $_; if ( !$found_2 ) { if ( $line ~= m/^2/ ) { $found_2 = 1; } else { substr($line, 99, 1, "9"); substr($line, 148, 1, "Z"); } } print OUTPUT $line; }