0

perl cgi で 2 つの配列またはファイルを使用してテーブルを作成するには、ヘルプが必要です。

別のパスからディレクトリのリストを出力するテーブルを作成し、それをテーブルに配置する必要があります.1列目のタイトルはpath1、2列目はpath2などで、各列にはそのパスからのディレクトリがhrefリンクでリストされています..ここに私が持っているものがあります。

 opendir(D, "../abc/status") or die"$!"; 
 my @path1_dir = sort readdir D; closedir D;

 opendir(D, "../def/status") or die "$!"; 
 my @path2_dir = sort readdir D; closedir D; .... ...

 print "\n"; print "$path1_dir\n"; print "$path2_dir\n";

 #print list of directories to column-1 with title Path1
 foreach my $path (@path1_dir) { 
   print "\t\n"; 
   next if ($path =~ /^./); 
   next if ($path =~ /^\s*$/); 
  print "$path\n"; 
 }

 #this should go to the column two with Path2 title but it does not
 foreach my $path (@path2_dir) { 
   print "\t\n"; `enter code here`
   next if ($path =~ /^./); 
   next if ($path =~ /^\s*$/); 
   print "$path\n"; 
   }

できれば、誰かがこれについて私を助けることができますか?

4

2 に答える 2

0

あなたの説明に基づいて、このようなものが必要だと思います-つまり、2列で印刷します

    $dir1 = "../abc/status";
    $dir2 = "../def/status";
    opendir(D, $dir1) or die"$!";
    my @path1_dir = sort grep { !/(^\.|^\s*$)/ } readdir D; closedir D;

    opendir(D, $dir2) or die "$!"; 
    my @path2_dir = sort grep { !/(^\.|^\s*$)/ } readdir D; closedir D;

    print "$dir1\t$dir2\n";

    # figure out which one has more files
    $limit = $#path1_dir < $#path2_dir ? $#path2_dir : $#path1_dir;

    # print in 2 columns
    for ($i = 0; $i<=$limit; $i++) {
       printf "%s\t%s\n",
            ($i<=$#path1_dir ? $path1_dir[$i] : ""),
            ($i <= $#path2_dir ? $path2_dir[$i] : ""),"\n";
    }
于 2013-10-23T18:39:41.197 に答える