- 论坛徽章:
- 145
|
按正则的规则可以创建文件,但是,下面的内容无法输出到此文件呀。
继续求教。
tener 发表于 2011-03-18 11:23 ![]() - use strict;
- my $sFile = "object-service-xx.txt"; # your file name here
- open(my $FHin, "<", $sFile) or die "can't open $sFile file \n";
- my $sOut_file = "";
- my $sOut_data = "";
- while(<$FHin>){
- if(m/^(object-service-a\d+)/){
- output($sOut_file, $sOut_data);
- $sOut_data = "";
- $sOut_file = "$1.txt";
- }
- else{
- $sOut_data .= $_;
- }
- }
- output($sOut_file, $sOut_data);
- #=================================
- sub output{
- my ($sFile, $sData) = @_;
- return if ($sFile eq "");
- open(my $FHout, ">>", $sFile) or die "can't open $sFile file\n";
- print {$FHout} $sData;
- close $FHout;
- }
复制代码 |
|