in reply to Re^2: Found a bug with Search and Replace command? (incremental)
in thread Found a bug with Search and Replace command?

Did you test this? I'm not claiming you are wrong, but my quick test of it showed it not changing anything:

#!/usr/bin/perl -w use strict; my $TEXT= do { local $/; <DATA> }; if( $TEXT =~ /abc/g ) { $TEXT =~ s/\G(\D+)([\d\.\-]*)­/$1GOVALUE/g; } print $TEXT; __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");

The output was the same as the input.

- tye        

Replies are listed 'Best First'.
Re^4: Found a bug with Search and Replace command? (incremental)
by Roy Johnson (Monsignor) on Mar 05, 2005 at 00:27 UTC
    Yes, I did test it.
    my $TEXT= do { local $/; <DATA> }; $TEXT =~ /abc/g; $TEXT =~ s/\G(\D+)([\d\.\-]*)/$1GOVALUE/g; print $TEXT; __END__ Some 01.35 numbers 019999 not to 01.055555 replace 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");
    outputs:
    Some 01.35 numbers 019999 not to 01.055555 replace abc(" GOVALUE, GOVALUE, GOVALUE, GOVALUE, GOVALUE",\ " GOVALUE, GOVALUE, GOVALUE, GOVALUE, +GOVALUE",\ " GOVALUE, GOVALUE, GOVALUE, GOVALUE, +GOVALUE",\ " GOVALUE, GOVALUE, GOVALUE, GOVALUE, +GOVALUE",\ " GOVALUE, GOVALUE, GOVALUE, GOVALUE, +GOVALUE"); GOVALUE
    The final GOVALUE is because it matches an empty string.

    Update: When I copy your code, I get a stealth trailing hyphen in the pattern space, and it fails to substitute.


    Caution: Contents may have been coded under pressure.

      Thanks. Sorry, I made a cut'n'paste mistake, including the soft hyphen that PerlMonks inserted for me when it displayed your code.

      I remember being disappointed by \G not working in some cases, you didn't show any test code, and I was busy, so I didn't investigate further after my quick test failed.

      - tye