CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [perl_oyster] How do I modify the line after a matched line?: Edit Log



FishMonger
Veteran / Moderator

Sep 30, 2011, 6:24 AM


Views: 5885
Re: [perl_oyster] How do I modify the line after a matched line?

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.


Code
#!/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)


Edit Log:
Post edited by FishMonger (Veteran) on Sep 30, 2011, 6:24 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives