in reply to Numbering instances of a String in a file
use strict; use warnings; my $cnt = 1; while (<>) { s/$/sprintf '%04d', $cnt++/e if /^\*+$/; print; }
Update: The above code functionally satisfies the OP specification. Thanks to ikegami for demonstrating several optimization techniques below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Numbering instances of a String in a file
by ikegami (Patriarch) on Jun 07, 2010 at 17:33 UTC | |
by JavaFan (Canon) on Jun 07, 2010 at 23:21 UTC | |
by ikegami (Patriarch) on Jun 08, 2010 at 03:37 UTC |