搜索
您的当前位置:首页perl语言入门第七八章作业

perl语言入门第七八章作业

来源:飒榕旅游知识分享网
7.1

Perl 源程序 use strict; use warnings;

while () { if (/fred/) { print $_; } } 运行结果

7.2

Perl 源程序 use strict; use warnings;

while () { #if (/[fF]red/) { if (/(f|F)red/) { #if (/fred|Fred/) { print $_; } } 运行结果

7.3

Perl 源程序 use strict; use warnings;

while () { #if (/\\./) { if (/[.]/) {

} }

print $_;

运行结果

7.4

Perl 源程序 use strict; use warnings;

while () { if (/[A-Z][a-z]+/) { print $_; } }

运行结果

7.5

Perl 源程序 use strict; use warnings;

while () { if (/(\\S)\\1/) { print $_; } }

运行结果

7.6

Perl 源程序 use strict; use warnings;

while () { if (/wilma/) { if (/fred/) { print $_; } } }

运行结果

8.1

Perl 源程序 use strict; use warnings;

while (<>) { chomp; if (/match/) { print \"Matched: | $`<$&>$' |\\n\"; }else { print \"No match: | $_ |\\n\"; } }

运行结果

8.2

Perl 源程序 use strict; use warnings;

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

}

}else { print \"No match: | $_ |\\n\"; }

运行结果

8.3

Perl 源程序 use strict; use warnings;

while (<>) { chomp; if (/(\\b\\w*a\\b)/) { print \"Matched: | $`<$&>$' |\\n\"; print \"\\$1 contains '$1'\\n\"; }else { print \"No match: | $_ |\\n\"; } }

运行结果

8.4

Perl 源程序 use strict; use warnings; use 5.010;

while () { chomp; if (/(?\\b\\w*a\\b)/) { print \"Matched: | $`<$&>$' |\\n\"; print \"'word' contains '$+{word}'\\n\"; }else { print \"No match: | $_ |\\n\"; } }

运行结果

8.5

Perl 源程序 use strict; use warnings;

while (<>) { chomp; if (m! (\\b\\w*a\\b) (.{0,5}) !xs) { print \"Matched: | $`<$&>$' |\\n\"; }else { print \"No match: | $_ |\\n\"; } }

运行结果

8.6

Perl 源程序 use strict; use warnings;

while (<>) { chomp; if (/\\s+$/) { print \"$_#\\n\"; } }

运行结果

因篇幅问题不能全部显示,请点此查看更多更全内容

Top