in reply to Re: Problems with matching?
in thread Problems with matching?

I added the reset later, with no effect. And how would I change the while m// to s///? I need to find what I am substituting first, right? I did update my_rand to deal with duplicates (will update code above).

Update1; Oh, put code within the substitution!!

Update2: How do I get it to loop? :/

Elda Taluta; Sarks Sark; Ark Arks

Replies are listed 'Best First'.
Re^3: Problems with matching?
by wind (Priest) on May 19, 2011 at 00:10 UTC

    if you just want to replace the first occurance of a name, then use the following

    my %new_names; $file =~ s{^\s+description\s\K(\w\w\w\w)(?=-\w+-\w+;)}{ my $name = $1; if (!$new_names{$name}) { $name = $new_names{$name} = my_rand(); } $name }gme;

    Or if you want to replace all occurances of a name with the new name, then the following would work:

    my %new_names; $file =~ s{^\s+description\s\K(\w\w\w\w)(?=-\w+-\w+;)}{ $new_names{$1} //= my_rand(); }gme;

    Note: since the suffix appears to not be relevant, I added it to the positive look ahead assertion.