这个perl替换字符串有什么作用?

时间:2013-04-12 18:13:49

标签: regex perl

我不知道这里发生了什么......我正在尝试手动执行此操作,而不是让Perl执行此操作。

my $replace_string
    = "s/typedef struct WebFontDescription WebFontDescription/struct WebFontDescription/g";

print $fh "perl -p -i -e \""
        . $replace_string
        . "\" \""
        . $idl_filename
        . "\"\r\n";

$replace_string
    = "s/\(WebFontDescription\\* webFontDescription/\(struct WebFontDescription\\* webFontDescription/g";

print $fh "perl -p -i -e \""
        . $replace_string
        . "\" \""
        . $idl_filename
        . "\"\r\n";

我看到它找到了一个字符串

typedef struct WebFontDescription WebFontDescription

然后用

替换它

s/\(WebFontDescription\\* webFontDescription/\(struct WebFontDescription\\* webFontDescription/g

但是如何用正则表达式替换正则表达式?这没有任何意义......

1 个答案:

答案 0 :(得分:4)

它创建以下一对shell命令:

perl -p -i -e "s/typedef struct WebFontDescription WebFontDescription/struct WebFontDescription/g" "file"
perl -p -i -e "s/(WebFontDescription\* webFontDescription/(struct WebFontDescription\* webFontDescription/g" "file"

第一个替换

的每个实例
typedef struct WebFontDescription WebFontDescription

struct WebFontDescription

第二个没有做任何事情,但抛出一条错误信息,因为它没有编译。 (不匹配(。)

相关问题