免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1876 | 回复: 3
打印 上一主题 下一主题

如何用perl实现:获取定位的一段文字 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-23 21:57 |只看该作者 |倒序浏览
比如说我要获取[Question 1.10] 到 [Question 1.11] 这一段中的文字,请教一下各位如何实现

  1. #!/usr/bin/perl -w
  2. use strict;
  3. my @article=();
  4. #my $sourcefile = $ARGV[0];
  5.         #open(SFHD,"$sourcefile");
  6.         while(<DATA>)
  7.         {
  8.                 if(!@article && /^\s*$/){print; next}
  9.                 push @article,$_;
  10.                 if(/\[Question 1\.10\](.*)\[Question 1\.11\]/s)
  11.                 {
  12.                         print $1;
  13.                 }

  14.         }

  15. __DATA__
  16. [Question 1.10] Which two options will influence the frequency of checkpoints?(Choose two.)
  17. A.the value that is specified for the LOG_CHECKPOINT_TO_ALERT parameter
  18. B.the size of the data files
  19. C.the size of the control file
  20. D.the value that is specified for the PGA_AGGREGATE_TARGET parameter
  21. E.the value that is specified for the FAST_START_MTTR_TARGET parameter
  22. F.the size of redo log files
  23. Correct Answers: E,F
  24. [Question 1.11] Which two statements regarding the database writer (DBWn)
  25. background process are true? (Choose two.)
  26. A.It writes dirty buffers to the data files before the log writer (LGWR)
  27. writes.
  28. B.It is an optional background process.
  29. C.It writes dirty buffers to the data files whenever a transaction
  30. commits.

复制代码

论坛徽章:
0
2 [报告]
发表于 2009-06-23 22:27 |只看该作者
如果你的格式不变的话,可以这么做

-----------


#!/usr/bin/perl
use strict;
use warnings;

$_ = join '', <DATA>;

print $1 if /\](.*?)\[/s;


__DATA__
[Question 1.10] Which two options will influence the frequency of checkpoints?(Choose two.)
A.the value that is specified for the LOG_CHECKPOINT_TO_ALERT parameter
B.the size of the data files
C.the size of the control file
D.the value that is specified for the PGA_AGGREGATE_TARGET parameter
E.the value that is specified for the FAST_START_MTTR_TARGET parameter
F.the size of redo log files
Correct Answers: E,F
[Question 1.11] Which two statements regarding the database writer (DBWn)
background process are true? (Choose two.)
A.It writes dirty buffers to the data files before the log writer (LGWR)
writes.
B.It is an optional background process.
C.It writes dirty buffers to the data files whenever a transaction
commits.

论坛徽章:
0
3 [报告]
发表于 2009-06-23 22:45 |只看该作者
谢谢啦,
能跟我解释一下
$_ = join '', <DATA>;

这一句吗

论坛徽章:
0
4 [报告]
发表于 2009-06-23 22:53 |只看该作者
join EXPR,LIST
Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example:

    $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);

Beware that unlike split, join doesn't take a pattern as its first argument. Compare split.


----------

呃,其实就是 perldoc -f join

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP