use re 'eval';
$ConstRegex = '^(.+).?(??{reverse $1})$';
@hairetu = ();
push(@hairetu,'abc');
push(@hairetu,'abbb');
push(@hairetu,'ddd');
push(@hairetu,'dddd');
push(@hairetu,'abccba');
push(@hairetu,'abcba');
push(@hairetu,'abcdedcba');
push(@hairetu,'11');
push(@hairetu,'111');
push(@hairetu,'1111');
push(@hairetu,'tomato');
push(@hairetu,'racecar');
push(@hairetu,'wasitabarorabatisaw');
push(@hairetu,'abcdeffedcba');
push(@hairetu,'abcdefghijk');
push(@hairetu,'abcdefedcba');
print ("Pattern $ConstRegex\n");
for ($i=0; $i <= @hairetu-1; $i++) {
$LineNo = $i+1;
$willOut = "Line$LineNo $hairetu[$i] ";
if ($hairetu[$i] =~ m/$ConstRegex/){
$willOut .= "matchs $&";
}
else{
$willOut .= 'no match'
}
print "$willOut\n";
}
#実行結果
Pattern ^(.+).?(??{reverse $1})$
Line1 abc no match
Line2 abbb no match
Line3 ddd matchs ddd
Line4 dddd matchs dddd
Line5 abccba matchs abccba
Line6 abcba matchs abcba
Line7 abcdedcba matchs abcdedcba
Line8 11 matchs 11
Line9 111 matchs 111
Line10 1111 matchs 1111
Line11 tomato no match
Line12 racecar matchs racecar
Line13 wasitabarorabatisaw matchs wasitabarorabatisaw
Line14 abcdeffedcba matchs abcdeffedcba
Line15 abcdefghijk no match
Line16 abcdefedcba matchs abcdefedcba