
FishMonger
Veteran
/ Moderator
Sep 30, 2011, 6:24 AM
Post #6 of 6
(9789 views)
|
Re: [perl_oyster] How do I modify the line after a matched line?
[In reply to]
|
Can't Post
|
|
What compatibility issues are you worried about? File::Find is one of the core modules that comes with Perl, so it won't have any compatibility issues. There are several ways to accomplish what you need without the module. Since you didn't provide complete/proper specs, I can't guaranty this will do what you want, but should be very close.
#!/usr/bin/perl use strict; use warnings; print "Starting script\n\n"; my $file_name = "test.txt"; open my $fh, '<', $file_name or die "could not open '$file_name' $!"; while ( my $line = <$fh> ) { if ( $line =~ /your pattern/ ) { print $line; my $next_line = <$fh>; $next_line =~ s/change this/to something/; print $next_line; } else { print $line; } } close $fh;
(This post was edited by FishMonger on Sep 30, 2011, 6:24 AM)
|