perl 练习题利用模式测试程序匹配以a为结尾的单词

回复 收藏
先给出一个测试用的文本文件:
cat ./test.txt
Helo, This is a test file.
This file contain a story about fred flintstone and his friend.
One day fred went to shoping, he met Sam who is his friend.
Sam was also for shopping. So they got together.
lalalal fred or wilma.
When they on their way home, they met frederick and Alfred.
Frederick and Alfred want to look after their granpa Mr. Slate.
this line just test Fred
and this line FRED
add this line Bamm-Bamm
wilma and fred
aa
abcdefhijk
foot
goooood

perl程序为:
#! /usr/bin/perl
if (! open TEST,"./test.txt") {
        die $!;
}

while () {
        chomp;
        if (/\w*a\b/) {
                print "|$`<$&>$'\n";
        }
}

运行结果为:
|Helo, This is test file.
|This file contain
story about fred flintstone and his friend.
|lalalal fred or .
|Frederick and Alfred want to look after their  Mr. Slate.
| and fred
|
2012-12-17 15:37 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: