文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>perl的文件操作

perl的文件操作

时间:2011-05-12  来源:孤独的猫

假如有一个从WEB上拷贝下来的文件

01 #!/usr/bin/perl -w 

02   

03 use Tk; 

04   

05 $Tk::strictMotif = 1; 

06   

07 $main = MainWindow->new(); 

08   

09 $button1 = $main->Button(-text => "Exit", 

10                          -command => \&exit_button, 

11                          -foreground => "orangered" ); 

12   

13 $button1->pack(); 

14 $button1->configure(-background => "white" ); 

15 $button2 = $main->Button(-text => "Push Me", 

16                          -command => \&change_color, 

17                          -foreground => "black",  

18                          -background => "steelblue"); 

19   

20 $button2->pack(); 

21   

22 MainLoop(); 

23   

24 sub exit_button { 

25     print "You pushed the button!\n"; 

26     exit; 

27 } 

28   

29 sub change_color { 

30     $button1->configure(-background => "red", 

31                         -foreground => "white"); 

32     $button2->configure(-background => "maroon", 

33                         -foreground => "white", 

34                         -font       => "-*-times-bold-r-normal-20-140-*"); 

35 }

现在想去掉其中的前导数字和空格,可用以下代码解决(打印在屏幕上)

use strict;
use warnings;

my $file="./s1";

if (! open (FILE,"$file")) {
    die "can not open file"
}

while (<FILE>) {
  chomp;
  if (/^(\d+\s+)(\S+)/) {   #如果存在前导数字和空格并且不是空代码行,去掉此句将保留空行
    s/^(\d+\s+)//;           #替换前导数字和空格
    print "$_\n";
  }
}

相关阅读 更多 +
排行榜 更多 +
正太寿司屋游戏安卓版下载

正太寿司屋游戏安卓版下载

模拟经营 下载
波比的游戏时间第七章手游下载

波比的游戏时间第七章手游下载

休闲益智 下载
像素火影(次世代)千手扉间下载

像素火影(次世代)千手扉间下载

飞行射击 下载