- 论坛徽章:
- 0
|
本帖最后由 风吹不倒 于 2012-01-02 21:00 编辑
大家好:
有一个需求,从配置文件中读取字符串格式应用到正则表达式中,比如配置文件内容如下:代码如下:- #!/usr/bin/perl -w
- open FH,"file";
- my $line =<FH>;
- my ($old,$new)=split /\s+/,$line;
- print "$old,$new\n";
- $old = qr/$old/;
- my $val = '0102wwwops';
- print "before:\t$val\n";
- $val =~ s/$old/$new/ee;
- print "after:\t$val\n";
复制代码 就能将wwwops替换为www,但使用多个括号来替换时却不行
- #cat file
- (www)o(p)s $1$2
复制代码 我想将wwwops变为wwwp,但出现了报错,是何问题,请大侠们帮助!
- Scalar found where operator expected at (eval 1) line 1, near "$1$2"
- (Missing operator before $2?)
- Use of uninitialized value in substitution iterator at sep.pl line 9, <FH> line 1.
复制代码 |
|