亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2343 | 回復: 9
打印 上一主題 下一主題

擷取檔案內容輸出到多個檔案問題 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2013-09-03 15:32 |只看該作者 |倒序瀏覽
#!/usr/bin/perl
use strict;
#use warnings;

my $file = $ARGV[0];
open my $info, $file or die "Could not open $file: $!";
my $cell_name;
my $flag = 0;

while( my $line = <$info>)  {   

                if($line=~ m/subckt\s+/ || $flag){
                        $flag =1;
                        if($line=~ m/subckt\s+(\w+)/){
                                $cell_name=$1;
                                print "--->>>>  cell name:".$cell_name."\n\n";   
                        }
                       
                        print $line;  
                         
                }
                if($line=~ m/ends/){
                        $flag =0;
                       
               
}
}
close $info;

====================================================
我把輸入檔案所有subckt到ends的內容都擷取出來
怎麼樣把一段subckt到ends的內容輸出到一個檔案~
也就是說有幾個subckt到ends就會有幾個輸出檔案
檔案名稱用$cell_name

目前差這一步 該如何修改

謝謝各位大大!!!

論壇徽章:
0
2 [報告]
發(fā)表于 2013-09-03 16:01 |只看該作者
  1. my $file = $ARGV[0];
  2. open my $info, $file or die "Could not open $file: $!";
  3. my ( $flag, $fh, $cell_name ) = 0;

  4. while ( my $line = <$info> ) {
  5.     if ( $line =~ m/subckt\s+/ || $flag ) {
  6.         $flag = 1;
  7.         if ( $line =~ m/subckt\s+(\w+)/ ) {
  8.             $cell_name = $1;
  9.             open $fh, '>', $cell_name or die $!;
  10.         }
  11.         print $fh $line;
  12.     }
  13.     if ( $line =~ m/ends/ ) {
  14.         $flag = 0;
  15.         close $fh;
  16.     }
  17. }
  18. close $info;
復制代碼

論壇徽章:
8
技術圖書徽章
日期:2013-09-30 08:51:28技術圖書徽章
日期:2013-12-11 09:26:39白羊座
日期:2013-12-27 15:27:13金牛座
日期:2014-01-06 09:13:05天蝎座
日期:2014-01-21 14:23:28酉雞
日期:2014-05-09 16:51:12卯兔
日期:2014-08-11 16:49:1515-16賽季CBA聯賽之八一
日期:2017-08-14 23:24:57
3 [報告]
發(fā)表于 2013-09-03 16:18 |只看該作者
本帖最后由 xiumu2280 于 2013-09-03 16:19 編輯

my @data;
if((@data)=$line=~ m/subckt\s+(\w+)/g){
                 print "@data";
}

論壇徽章:
0
4 [報告]
發(fā)表于 2013-09-03 16:22 |只看該作者
cinanine 發(fā)表于 2013-09-03 16:01


再次謝謝cinanine!!! 可以了

論壇徽章:
0
5 [報告]
發(fā)表于 2013-09-03 17:13 |只看該作者
cinanine 發(fā)表于 2013-09-03 16:01


麻煩再請教cinanine大大!!

我如果輸出檔案不要含ends那行的話
該如何修改!!

謝謝

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯賽之青島
日期:2016-03-17 20:36:13
6 [報告]
發(fā)表于 2013-09-04 01:17 |只看該作者
試試:
  1. #!/usr/bin/perl
  2. my $file = $ARGV[0];
  3. open my $info, $file or die "Could not open $file: $!";
  4. my $F;

  5. while (<$info>) {
  6.     /subckt\s+(\w+)/ and open $F, '>', $1;
  7.     /ends/ or print $F $_;
  8. }
復制代碼

論壇徽章:
0
7 [報告]
發(fā)表于 2013-09-06 09:39 |只看該作者
回復 6# rubyish

大大 好像會有ERROR耶
   

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術圖書徽章
日期:2014-03-05 01:33:12技術圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯賽之青島
日期:2016-03-17 20:36:13
8 [報告]
發(fā)表于 2013-09-08 22:37 |只看該作者
回復 7# kfcdog0419


       這位大大! 怎麼樣的 ERROR ?

論壇徽章:
0
9 [報告]
發(fā)表于 2013-09-09 13:32 |只看該作者
對于這種需求: “我把輸入檔案所有subckt到ends的內容都擷取出來” , 最好的辦法是按多行模式進行匹配分割,一會兒上示例程序

論壇徽章:
0
10 [報告]
發(fā)表于 2013-09-09 13:48 |只看該作者
$ cat -n test2.pl
     1  use strict;
     2  use warnings;
     3  use Data::Dumper;
     4
     5
     6  exit(main(@ARGV));
     7
     8  sub dumpToFile{
     9      my $record = shift;
    10      my ( $filename ) = ( $record =~ /subckt:\s*(\w+)/);
    11      open my $fd ,">",$filename or die "failed to open $filename,$!";
    12      print $fd $record;
    13      close $fd;
    14  }
    15
    16
    17  sub main{
    18      my $text = <<'END';
    19  subckt: ckpt1
    20  date: 2013-09-01
    21  description: xxxxxxxxxxxx
    22  end
    23  subckt: ckpt2
    24  date: 2013-09-02
    25  description: xxxx
    26  end
    27  subckt: ckpt3
    28  description: xxxxxxxx
    29  date: 2013-09-03
    30  end
    31  END
    32
    33      my @records = split(/(?=subckt)/, $text);
    34      foreach my $record (@records) {
    35          dumpToFile( $record );
    36      }
    37  }
    38
    39

$ perl test2.pl
$ ls
ckpt1  ckpt2  ckpt3  test.pl  test2.pl
$ cat ckpt1
subckt: ckpt1
date: 2013-09-01
description: xxxxxxxxxxxx
end

Fei@HPenvy ~/mycode
$ cat ckpt2
subckt: ckpt2
date: 2013-09-02
description: xxxx
end

Fei@HPenvy ~/mycode
$ cat ckpt4
cat: ckpt4: No such file or directory

Fei@HPenvy ~/mycode
$
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯網協會會員  聯系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP