各位大大,目前要處理字串重新排列的問題
透過split+substr,能夠完成,但是$FLOW宣告的方式有點怪,
想了解有沒有更好的寫法呢? 謝謝
<以下是字串與code內容:>
=====字串======
OPEN_SHORT ? : #C(hw_fail_1, sw_fail_1 ) ; //AA
MBIST ? : #C(hw_fail_2, sw_fail_2 ) ;//BB
last_item? #C(pass, pass) : #C(hw_fail_3, sw_fail_3 ) ;
=====執行程式的輸出=====
OPEN_SHORT ? : #C(hw_fail_1, sw_fail_1 );//AA
MBIST ? : #C(hw_fail_2, sw_fail_2 );//BB
last_item ? #C(pass, pass) : #C(hw_fail_3, sw_fail_3 );
=====程式=====
my $FLOW=' ';
my @Array=();
$FLOW =~ s/\)\s+\;/=/g;
$FLOW =~ s/\?|\:/=/g;
@Array = split(/\=/, $FLOW);
$Array[0] =~ s/\s+//g;
$Array[1] =~ s/^\s+|\s+$//g;
$Array[1] =~ s/\(\s+/(/g;
$Array[1] =~ s/(\w+)$/$1)/g;
$Array[2] =~ s/^\s+|\s+$//g;
$Array[3] =~ s/^\s+|\s+$//g;
substr($FLOW, 0,0) = 'Array[0]';
substr($FLOW, 16,0) = '? Array[1]';
substr($FLOW, 31,0) = ': Array[2]';
substr($FLOW, 56,0) = ');Array[3]';
print $FLOW;
--