Home: Perl Programming Help: Regular Expressions:
need perl matching - very urgent



abcindiaxyz
New User

Jan 20, 2008, 10:48 PM


Views: 8723
need perl matching - very urgent

Hi All,

I have some Languages with braces in my table

Note: It has all the languages the below are the examples of the languages that has braces

Ex: Altaic [other],Baltic [other],Bantu (other),Batak (Indonesia),Berber (other)


which comes from database, if user selects any of these Languages the match case mathes the value with all the Languages in database and
hilights the selected one as "selected" in list box.

the code which i'm using is

@olanglist[$i] is the array of all languages
@otherlang is the selected language

$i = 0;
while (@olanglist[$i]) {
foreach(@otherlang){
$olang = "<option>$_";
$_ = $olang;
if (m/@olanglist[$i]/){
@olanglist[$i] =~ s/\<option\>/<option selected>/o;
}
}
$i++;
}


but not the match case is not matching the values that has Braces ,rest all are fine ,

can any one pelse suggest me how to do it ?


KevinR
Veteran


Jan 20, 2008, 11:24 PM


Views: 8720
Re: [abcindiaxyz] need perl matching - very urgent

instead of:


Code
 if (m/@olanglist[$i]/){


try:


Code
 if (m/\Q$olanglist[$i]\E/){


using \Q..\E escapes the meta characters in the search pattern. I'm not sure this will actually solve your problem, but it has to be done anyway.

Also, you should not use @array[n] notation to access the individual elements of an array, use $array[n], which is the proper context.

Please do not use"urgent" in future posts. Your question will be answered or not answered like all other questions.
-------------------------------------------------


(This post was edited by KevinR on Jan 20, 2008, 11:26 PM)