Thursday, March 18, 2010

Perl: Detecting two words concatenated into one sepearted by uppercase character

If you are given a word 'textArea' and want to be able to separate them into 'text Area', then here is the perl code to help you achieve it

$item = 'textAreaBuffer';
if($item =~ m/.*?[a-z].*?[A-Z]/){
$count=0;
@rem=();
while($item =~ m/([a-z][A-Z])/g){
$rem[$count]=pos($item);$count=$count+1;

}

for($count=0;$count<@rem;$count++){
if($count==0){
print FILE2 substr($item,0,$rem[$count]-1);
print FILE2 " "; }
else{
print FILE2 substr($item,$rem[$count-1]-1,$rem[$count]-$rem[$count-1]);
print FILE2 " ";
}
}
print FILE2 substr($item,$rem[@rem-1]-1);
print FILE2 " ";
}

No comments:

Post a Comment