perl

#!/usr/bin/perl
 use 5.016;

open IN,'<',"in.txt";
my $portcnt =0;
my $namecnt =0;
my $wirecnt =0;
while (<IN>){
     next if /^\s$/;
     if(/\.\s*(?<port>\w+)\s*\(\s*(?<name>\w+)\s*\)/){
         if ((length ($+{port}))>$portcnt){
             $portcnt = length ($+{port});
         }
         if ((length ($+{name}))>$namecnt){
             $namecnt = length ($+{name});
         }
     }elsif(/(?<wirename>wire.*);/){
          if ((length ($+{wirename}))>$wirecnt){
         $wirecnt = length ($+{wirename});
         }
     }
 }

close(IN);

say $wirecnt;
say $portcnt;
say $namecnt;

open IN,'<',"in.txt";
while (<IN>){
    open (my $out,'>>',"out.txt");
    if(/(?<wirename>wire.*);/){
         printf $out "%-23s;//\n",$+{wirename};
        }elsif(/\.\s*(?<port>\w+)\s*\(\s*(?<name>\w+)\s*\)/){
         printf $out ".%-25s( %-30s ),\n",$+{port},$+{name};        
         }else {
         printf $out "$_";     
         }
          close ($out);
     }



     

 

 

posted @ 2017-05-27 07:11  毛小子  阅读(187)  评论(0)    收藏  举报