in reply to Modify a txt file
If you look at each grouping as a record, and set the input record separator to "\n\n" (which is what appears to separate the records in your example), it gets really easy:
use strict; use warnings; $/ = "\n\n"; while ( <DATA> ) { if( my( $number ) = m/(\d+)/ ) { s/\b\p{Alpha}+\b/$number/g; } else { warn "Malformed record in input line $.\n$_\nContinuing.\n"; } print; } __DATA__ 0 ASDF ASEE ASEE 13 DERG DREG 28 QWER QWER 42 WERT WERT WERT 55 QWEASD QWEASD QWEASD QWEASD
Here is the output from your test data:
0 0 0 0 13 13 13 28 28 28 42 42 42 42 55 55 55 55 55
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modify a txt file
by la (Novice) on Oct 20, 2011 at 05:51 UTC | |
|
Re^2: Modify a txt file
by la (Novice) on Oct 20, 2011 at 06:37 UTC | |
by GrandFather (Saint) on Oct 20, 2011 at 07:34 UTC | |
by davido (Cardinal) on Oct 20, 2011 at 06:56 UTC |