theboxlot has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I have the following file with records as follows:
Apple*Red*12~ Pear*Green*~ Strawberry*Red*6~ Kiwi**~
Where the '*' is a field delimter and the '~' is a record delimter.

Q: Can the substitution operator search and replace the "*~" string with just a tilde? When '*' can repeat n times. (ie '***~' '**~' ... etc)

example output:
Apple*Red*12~ Pear*Green~ Strawberry*Red*6~ Kiwi~

Thanks in Advance

Replies are listed 'Best First'.
Re: Search & Replace "*~" String ?
by kvale (Monsignor) on Mar 19, 2004 at 18:44 UTC
    Sure:
    $line =~ s/\*+~/~/g;
    where the g flag should be present is if there is more the one of these sequences per line.

    -Mark