第七章:正则表达式

上一篇 / 下一篇  2008-11-12 11:28:33 / 个人分类:《Perl语言入门》-小骆驼书-练习题答案

1)
use warnings;## Copyright (C) 2008 by xjiang## Copyright (C) 2008 by xjiang## Copyright (C) 2008 by xjiang## Copyright (C) 2008 by xjiang
chomp (my @file = <>);
foreach (@file){
 if (/(fred)+/){
  print "\"$_\" contains fred.\n";
 } 
}

2)
use warnings;
chomp (my @file = <>);
foreach (@file){
 if (/[fF]red/){
  print "\"$_\" contains fred or Fred.\n";
 } 
}

3)
use warnings;
chomp (my @file = <>);
foreach (@file){
 if (/\.+/){
  print "\"$_\" contains '.' .\n";
 } 
}

4)
use warnings;
chomp (my @file = <>);
foreach (@file){
 if (/([A-Z][a-z])+/){
  print "\"$_\" matches pattern .\n";
 } 
}

5)
use warnings;
chomp (my @file = <>);
foreach (@file){
 if (/wilma.*fred|fred.*wilma/){
  print "\"$_\" contains 'wilma' and 'fred' .\n";
 } 
}
#while(<>){}


TAG:

 

评分:0

我来说两句

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 47613
  • 日志数: 80
  • 建立时间: 2008-10-27
  • 更新时间: 2009-07-17

RSS订阅

Open Toolbar