toniax has asked for the wisdom of the Perl Monks concerning the following question:
Hello again everyone, Sorry about being so cryptic last time I asked this. I will put my question in code. I created a way to do what I want but it seems so cumbersome. I am sure a better way exist? well here is the codeopen(XFIL,"var.txt") || die $!; @main = <XFIL>; close(XFIL); open(XFIL,">var.txt") || die $!; foreach $line (@main) { @main[0] =~ s/some data/this is the first line replaced/; print XFIL $line ; } close(XFIL);
open(XFIL,"var.txt") || die $!; @main = <XFIL>; close(XFIL); open(XFIL,">var.txt") || die $!; foreach $line (@main) { $line =~ s/\n/replace/g; print XFIL $line; } close(XFIL); open(XFIL,"var.txt") || die $!; @main = <XFIL>; close(XFIL); open(XFIL,">var.txt") || die $!; foreach $line (@main) { $line =~ s/the line to be replaced/this is the new line/; $line =~ s/replace/\n/g; print XFIL $line; } close(XFIL);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Better Way
by moritz (Cardinal) on Nov 04, 2010 at 16:37 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 16:54 UTC | |
by moritz (Cardinal) on Nov 05, 2010 at 06:50 UTC | |
by toniax (Scribe) on Nov 05, 2010 at 17:15 UTC | |
|
Re: A Better Way
by kcott (Archbishop) on Nov 04, 2010 at 17:21 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 17:34 UTC | |
by kcott (Archbishop) on Nov 04, 2010 at 18:10 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 18:22 UTC | |
by kcott (Archbishop) on Nov 04, 2010 at 18:43 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 22:13 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 18:29 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 18:53 UTC | |
|
Re: A Better Way
by eyepopslikeamosquito (Archbishop) on Nov 04, 2010 at 20:38 UTC | |
by toniax (Scribe) on Nov 04, 2010 at 22:53 UTC | |
|
Re: A Better Way
by talexb (Chancellor) on Nov 04, 2010 at 17:26 UTC |