in reply to Inserting a line in the middle of a text
Update: On second thought, the record length has nothing to do with it if you want to insert (I was thinking of an overwrite). You would still have to read the records in first somehow.#!/usr/bin/perl use strict; use warnings; my $infile = '/home/yanni/scripts/testfiles/list_names'; my $outfile = "$infile.tmp"; open (my $in, '<', $infile ) || die "Can't open $infile $!\n"; open (my $out, '>', $outfile) || die "Can't open $outfile $!\n"; while (<$in>) { print $out $_; if ($.== 3) {print $out "Simon\n";} } close ($in); close ($out); rename ($outfile, $infile) || die "Unable to rename: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inserting a line in the middle of a text
by JavaFan (Canon) on Jan 20, 2009 at 15:13 UTC | |
|
Re^2: Inserting a line in the middle of a text
by goude (Initiate) on Jan 20, 2009 at 12:17 UTC | |
by graff (Chancellor) on Jan 21, 2009 at 02:18 UTC |