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


你可能感兴趣的:(perl,替换字符串)