in reply to Re: Replacing, cutting, deleting lines in the file
in thread Replacing, cutting, deleting lines in the file
The file.txt contains this:my $array_position; my $file = "/home/user/file.txt"; open FILE, $file; my @file = (<FILE>); close FILE; foreach ( @file ) { if ($_ =~ /line 3/) { $array_position=$i+1; print "Position in array = ". $array_position. "\n"; } $i++; } for ($a=$array_position-1; $a<$array_position+3; $a++) { print "Postion ".$a." in the array = " .$file[$a]; } @array = @file; splice @array, 0, 'something'; print @array;
The problem is it doesn't want to replace first element from the array to string I specified. Any ideas why ? Regards, Jarekline 1 line 2 fsefse line 3 line 4 ,... line 5 line 6>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Replacing, cutting, deleting lines in the file
by gulden (Monk) on Nov 24, 2009 at 18:42 UTC | |
by Jarek (Novice) on Nov 25, 2009 at 09:08 UTC |