【发布时间】:2011-08-02 03:34:29
【问题描述】:
这个例子中 Perl 的 /m 修饰符是什么意思?
例如,假设我在 Example.txt 文本文件中有以下信息。每行以换行符结束,数据记录为Data 输入记录分隔符设置为:
$/="__Data__";
Example.txt
__Data__
This is test A.\n
This is test B.\n
This is test C.\n
This is test D.\n
问题1,将输入记录分隔符改为数据后,^和$字符的位置是否如下?
^__Data__
This is test A.\n
This is test B.\n
This is test C.\n
This is test D.\n$
问题 2,假设我在输入记录分隔符仍设置为 Data 的情况下使用 /m 修饰符,是否会将 ^ 和 $ 字符设置为以下?
^__Data__$
^This is test A.\n$
^This is test B.\n$
^This is test C.\n$
^This is test D.\n$
if(/__Data__/m)
{
print;
}
【问题讨论】:
-
你在 Perl 中做过这个实验吗?
-
是的,但我不清楚如何测试 ^ 和 $ 的位置。使用这个论坛来帮助澄清我的理解。
-
编辑清理这个问题和标题将有助于新用户不会因为原来是一个有趣的问题而被否决。
标签: perl