Perl_ディレクトリや拡張子の処理 - アールメカブ

アールメカブ


Perl_ディレクトリや拡張子の処理

Programming

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

open(LIST,"$ARGV[0]"); #解析対象ファイルのリスト
while($file = <LIST>){
 chomp($file);
 if($file =~ /\/(\w+)\.*(\w+)*$/){
   $newfile = $1;
   print "$newfile\n";
 }
 else{
   $newfile = $file;
 }

そのほか,昔,こんなのも書いている.良く思い出せないが,妙なことしているなぁ. 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";
  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+)/){
##      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";
  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+)/){
      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);
 
Link: Programming(5180d) 日録2007_10月(6207d)
Last-modified: 2007-10-09 (火) 17:48:04 (6239d)