in reply to Re: Re: string substitution
in thread string substitution

$string =~ s/\bHELL\b/BAD/g; $string =~ s/(?<\W)\s|\s(?=\W)//g;
First pass does the HELL -> BAD substitution based on word boundries. So far none of your examples have shown characters that are not either mathematical symbols, alpha, or space. So I'm not going to waste your time with worrying about whether BAD is next to a mathematical symbol. If your examples showed non-mathematical symbols, then I'd worry about that part again.

The second pass removes any whitespace that has a non-word character on one side or the other of it. That will get rid of the space between BAD and +, but not between REALHELL and REALHELL.

Until we know what you're really trying to do we will continue playing the guessing game and falling short of your needs. Be sure to read perlretut and perlre. It's your turn to come up with a solution.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: Re: Re: string substitution
by Anonymous Monk on Oct 09, 2003 at 19:16 UTC
    Thanks Dave,

    I will read as recommended. As an aside, I appreciate your help. Using \b...\b worked perfectly.

    For those who care, I am building an application that will parse sar files on any UNIX machine running sar (aix, solaris, hp-ux, sgi, linux, etc.) and either:

    1) create a graph of user selected data (selected by option & date(s)

    2) apply performance tuning rules for that specific OS (version & OS) based upon en expert system & rules base.

    This question dealt directly with the rules base, namely converting:

    ((0 < SML_MEM_FAIL ) or (0 < LG_MEM_FAIL ) or (0 < OVSZ_MEM_FAIL )) and ( FREEMEM <= 64 )

    without being to picky about spaces and the such.

    thanks

    g