I have the following subroutine OutputingReorderedVectors, which aims to output vectors following some pre-specified requirements. However, the code just output blank files.
I think the problem should come from this following code segment, which involves re-order the key from the second-level hash of chainRollupDoc
my @rollupArray = sort keys %chainRollupDoc;
my @reorderedSS = ();
foreach my $i(0 .. $#rollupArray)
{
foreach my $cui (sort keys %{$chainRollupDoc->{$rollupArray[$i]}})
{
push @reorderedSS, $cui;
}
}
The whole subroutine is in the following
#####################################
sub OutputingReorderedVectors
#####################################
{
my $centroids = shift;
my $fileName = shift;
my $chainRollupDoc = shift;
my @rollupArray = sort keys %chainRollupDoc;
my @reorderedSS = ();
foreach my $i(0 .. $#rollupArray)
{
foreach my $cui (sort keys %{$chainRollupDoc->{$rollupArray[$i]}})
{
push @reorderedSS, $cui;
}
}
my %attributes = ();
foreach my $category (keys %$centroids)
{
foreach my $cui (keys %{$centroids->{$category}})
{
$features{$cui} = 1;
}
}
my @fullSpace = sort keys %attributes;
open(OUTPUT, "> $fileName");
foreach my $i(0 .. $#reorderedSS)
{
printf OUTPUT "\t%s", $reorderedSS[$i];
}
print OUTPUT "\n";
foreach my $i (0 .. $#fullSpace)
{
printf OUTPUT "%s", $fullSpace[$i];
foreach my $j (0 .. $#reorderedSS)
{
printf OUTPUT "\t%f", $centroids->{$reorderedSS[$j]}->{$fullSpace[$i]};
}
print OUTPUT "\n";
}
close OUTPUT;
}
use strict;anduse warnings;? I've only been programming in Perl about 20 years and I know I don't spot all the problems that they do, so I essentially never code Perl without them.for my $i (0 .. $#array)usefor my $elem (@array)use strictanduse warningsuntil you know exactly why it is recommended to do so.