On Nov 28, Leon said:
>(Q1) How to put these three substitutions into one single substitution
>regex.
>$a =~s/</lt/;
>$a =~s/>/gt/;
>$a =~s/\\n/<br>/;
You should have the /g modifier on those regexes. But here's how to mash
them into one:
my %translate = qw( < lt > gt \n <br> );
my $pat = join '|', map quotemeta, keys %translate;
$a =~ s/($pat)/$translate{$1}/g;
If you want to do that, that's up to you.
>(Q2) How to do the following :-
> If there are 2 spaces, I wish to convert it into 1   like
>this => 
> 3 spaces into 2   like this =>   
> 4 spaces into 3   like this =>    
I would do something like this:
s/ ( +)/' ' x length($1)/g;
That matches a space and then one or more spaces and stores the "one or
more" part in $1. The length of $1 is 1 less than the number of spaces
found.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]