walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
I know, a very simple example, but I think it gets the idea across. Rather than opening and writing to a new file, I just want to replace the line in the file that we are working with. I want to update the $time lets say. See below for a BEFORE/AFTER example.#!/usr/bin/perl while (my $line=<>) { my ($blah,$blah2,$bla,$time,$blah3)=split(/:/,$line); if ($blah eq "test") { $time="UNDEF"; # Replace line in same file. } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replace current line in while loop
by tilly (Archbishop) on May 13, 2009 at 18:17 UTC | |
|
Re: Replace current line in while loop
by roboticus (Chancellor) on May 13, 2009 at 18:17 UTC | |
|
Re: Replace current line in while loop
by mr_mischief (Monsignor) on May 13, 2009 at 18:45 UTC | |
|
Re: Replace current line in while loop
by kennethk (Abbot) on May 13, 2009 at 17:51 UTC | |
by walkingthecow (Friar) on May 13, 2009 at 18:17 UTC | |
by tilly (Archbishop) on May 13, 2009 at 18:23 UTC | |
by Marshall (Canon) on May 13, 2009 at 18:36 UTC | |
by kennethk (Abbot) on May 13, 2009 at 18:21 UTC |