I was trying to grep string "Distance: " from "pairsAngles.txt" within each of over 2,000 subdirectories; the names of the subdirectories are obtained from a csv file.
However, the following code only give me a huge single line of output in csv format which I couldn't even open with an text editor:
my @pairs=qw();
my @result=();
my $in;
my $out;
my $pairs;
my $dist = "";
my $dir = "/home/avabelieve/aaPROJECT/helicalPair_ax/selectedPairs/renumberedPdb/clusterPairs-1.25-12-05_windows.12.resle3.2A.RMSD1.3/oligomerAngle";
my $cluster = "clst1.csv";
open ($in, $cluster) || die "cannot open \"$cluster\": $!";
my $cU = "clst1Updated.csv";
open ($out, ">$cU") || die "cannot open '$cU' $!";
my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
while (my $c1 = <$in>) {
chomp $c1;
push @pairs, $c1;
foreach $c1 (uniq @pairs) {
find (\&Matches, "$dir/$c1");
sub Matches {
open ($pairs, "oligomerAngles.out") or die "$!";
while (my $dist = <$pairs>) {
if ($dist =~ m/Distance: /){
chomp $dist;
push (@result, "$dist\n");
@result = split ": ", $dist;
}
}
} } chdir "..";
if (not $csv->eof) {
$csv->error_diag();
}
$csv->print ($out, [uniq @pairs, @result]);
}
close $out or die "$!";