in reply to Found a bug with Search and Replace command?
#!/usr/bin/perl -w use strict; my $TEXT= do { local $/; <DATA> }; my $result; if( $TEXT =~ /(.*?abc)/g ) { $result= $1; while( $TEXT =~ /\G(\D+)([\d.\-]+)/g ) { $result .= $1 . "GOVALUE"; } $result .= substr( $TEXT, pos($TEXT) ); } print $result; __END__ abc(" 0.123511, 0.074997, 0.103143, 0.153955, +0.260586",\ " 0.068394, 0.082183, 0.110329, 0.16114 +2, 0.267773",\ " 0.081887, 0.095677, 0.123822, 0.17463 +5, 0.281266",\ " 0.111534, 0.125324, 0.153470, 0.20428 +2, 0.310914",\ " 0.165731, 0.179521, 0.207666, 0.25847 +9, 0.365110");
Makes one wish you could do incremental s///g (like m//g in a scalar context), though we'd need something like an extra option to request such. s///gc or s///G (belg4mit's) anyone? Of course, it would probably be less efficient than the above code (requiring the entire end of the string to be copied/moved multiple times), but it would be less error-prone.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Found a bug with Search and Replace command? (incremental)
by Roy Johnson (Monsignor) on Mar 04, 2005 at 23:45 UTC | |
by tye (Sage) on Mar 05, 2005 at 00:11 UTC | |
by Roy Johnson (Monsignor) on Mar 05, 2005 at 00:27 UTC | |
by tye (Sage) on Mar 05, 2005 at 02:09 UTC |