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: [wickedxter] How do I modify the line after a matched line?: Edit Log



perl_oyster
New User

Sep 18, 2011, 10:44 PM


Views: 6351
Re: [wickedxter] How do I modify the line after a matched line?

I am trying something like this:


Code
#!/usr/bin/perl 
use strict;
use warnings;

print "Starting script\n\n";

my $file_name = "test.txt";

my $pos = 0;

open (FILE, $file_name) or die ("File could not be found!!");

while (<FILE>) {

if (/pattern/) {

$pos = tell(FILE);
$line = $.;
# Get length of current line in bytes (characters)
$length_of_line = #Need help here to calculate this
#Calculate offset
$offset = $length_of_line + $pos;
#Now go to next line (offset from current location)
seek(FILE, $offset, 1) or die "Couldn't seek to $offset: $!\n";

#Now perform the substitution

} else {next};
}

print "End script\n";

close(FILE);


I am trying to avoid lists. Is this doable?


(This post was edited by perl_oyster on Sep 18, 2011, 10:45 PM)


Edit Log:
Post edited by perl_oyster (New User) on Sep 18, 2011, 10:45 PM


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

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