Perl_ディレクトリや拡張子の処理 のバックアップの現在との差分(No.1) - アールメカブ

アールメカブ


Perl_ディレクトリや拡張子の処理 のバックアップの現在との差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[Programming]]

引数からディレクトリや拡張子をのぞく.手抜きの処理.

open(LIST,"$ARGV[0]"); #解析対象ファイルのリスト
while($file = <LIST>){
 open(LIST,"$ARGV[0]"); #解析対象ファイルのリスト
 while($file = <LIST>){
  chomp($file);
  if($file =~ /\/(\w+)\.*(\w+)*$/){# ディレクトリ指定や拡張子の有無にかかわらず
  if($file =~ /\/(\w+)\.*(\w+)*$/){
    $newfile = $1;
    print "$newfile\n";
  }

  else{
    $newfile = $file;
  }

そのほか,昔,こんなのも書いている.良く思い出せないが,妙なことしているなぁ.

 /home/ishida/research/Tex/paper/p2006/Altmann/altmann.results.pl
research/Tex/paper/p2006/Altmann/altmann.results.pl
 
 #!/usr/bin/perl
 
 open(OUT, ">/home/ishida/results.csv");
 
 opendir(DIR, "/home/ishida/goodness");#goodness
 @file = readdir(DIR);
 closedir(DIR);
 
 
 foreach $target (@file) {
   next if( $target =~ /^\./ or $target =~ /^result/);
   open(IN, "/home/ishida/goodness/$target") or die "cant access $target\n";
   open(IN, "/home/ishida/goodness/$target")
         or die "cant access $target\n";
   while($each_row = <IN>){
     chomp($each_row);
     $each_row =~ s/ //g;
     if($first == 0 and $each_row =~ /^Distribution/){
       next;
     }
     elsif($each_row =~ /^(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)/){
     elsif($each_row =~ 
         /^(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)/){
 ##      print $each_row."\n";
       $dist{$1} = 0;# "$2\t\$3\t$4\t$5\t$6";
     }
   }
   close(IN);
   
 }
 
 print OUT "\t";
 foreach $key (sort keys %dist){
   print OUT $key."\t";
 }
 print OUT "\n";
 
 ######### noch mal ########
 
 foreach $target (@file) {
   next if( $target =~ /^\./ or $target =~ /^result/);
   open(IN, "/home/ishida/goodness/$target") or die "cant access $target\n";
   open(IN, "/home/ishida/goodness/$target")
       or die "cant access $target\n";
   print OUT "$target\t";
   while($each_row = <IN>){
     chomp($each_row);
     $each_row =~ s/ //g;
 
     if($each_row =~ /^Distribution/){
       next;
     }
     elsif($each_row =~ /^(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)/){
     elsif($each_row =~
          /^(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)\t(\S+)/){
       if(exists $dist{$1}){
         $dist{$1} = "$2,$3,$4,$5,$6";     
       }
       else{
         $dist{$1} = "NA";
       }
     }
   }
   foreach $key (sort keys %dist){
     print OUT $dist{$key}."\t";
     $dist{$key} = "NA";
   }
   print OUT "\n";
 }
 
 close(OUT);