首页 > 代码库 > perl--简单的根据hash过滤替换字符串

perl--简单的根据hash过滤替换字符串

my %TEMP=(‘${TMP}‘=>‘SSS‘,
          ‘${PROJECT_ROOT}‘=>‘aaaaaaaa‘,
          ‘${MCB_PATH}‘=>‘bbbbbbbb‘,
          ‘${PATH}‘=>‘cccc‘,
          ‘${VERSION}‘=>‘ddddd‘
          );

while(<DATA>){ 
s/(\$\{.+?\})/$TEMP{$1}/ while $_=~/\$\{.+\}/;
print $_;
}

__DATA__
${TMP}/lib/common
${PROJECT_ROOT}/release
${MCB_PATH}/ac_s110      
${PATH}/${VERSION}/libc

结果:

SSS/lib/common
aaaaaaaa/release
bbbbbbbb/ac_s110
cccc/ddddd/libc


本文出自 “RZL_01的博客” 博客,请务必保留此出处http://rzl01.blog.51cto.com/3004337/1586112

perl--简单的根据hash过滤替换字符串