Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
open (IN, 'file.txt'); my $out = ''; my $newComment = 0; while (<IN>) { if(($newComment < 1) && ($_ ne /^\#|^--|^\/\/^\s*\/\*/|^\s*\*|\*\/ +$/)) { $out .= "#This file was updated with the fix"; $out .= "\n"; $newComment++; } $out .= $_; } open (OUT, '>output.txt'); print OUT $out or die "Can't print to OUT: $!"; close OUT; close IN; __DATA__ /* * This is the new function * It has the following parameters: * * 1. Filename * 2. URL */ # All the following are valid comment styles: # hello perl style -- hello sql style /* hello c style * continue c style end c style */ // c++ c style #Revision date: 2005-10-10 --start of file <-- here is where the new comment should go. configurationtype=search url=http://www.google.com --End of file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inserting string only once after matching a pattern
by ikegami (Patriarch) on Nov 06, 2006 at 06:31 UTC | |
by Anonymous Monk on Nov 06, 2006 at 06:52 UTC | |
by ikegami (Patriarch) on Nov 06, 2006 at 17:36 UTC | |
|
Re: inserting string only once after matching a pattern
by artist (Parson) on Nov 06, 2006 at 11:38 UTC |