in reply to Adding <pre> at beginning </pre> at file end
Compare the above to either keeping track of which line you're on from the input or slurping the input file into memory and doing a regex substitution over the whole thing. I think the KISS principle applies here.my $input = 'existing.txt'; my $output = 'new.txt'; open ( my $in, '<', $input ) or die "Cannot open file $input for readi +ng: $!\n"; open ( my $out, '>', $output ) or die "Cannot open file $output for wr +iting: $!\n"; print $out "<pre>\n"; while ( <$in> ) { print $out $_; } print $out "\n</pre>\n"; close $out or warn "Error writing $output: $!\n"; close $in;
|
|---|