A
Andrea Spitaleri
Hi,
the below code works great but I would like to receive some comment
about its perl-ish style. (I am not new posting this kind of messagge,
but I want improve my style)
the problem is: I have several file, which they need to be ranked.
i.e.:
1.sft contains rms 1
2.sft contains rms 3
3.sft contains rms 2
4.sft contains rms 0.5
5.sft contains rms 3
........
and I would like to get at the end symbolic link, ranking the file bye
rms values:
rank_1.sft ---> 4.sft
rank_2.sft ---> 1.sft
rank_3.sft ---> 3.sft
rank_4.sft ---> 2.sft
rank_5.sft ---> 5.sft
.........
#!/usr/bin/perl
use warnings;
foreach my $index (1 .. $ARGV[0]){
open (FILE,"<$index.sft") || die "cannot open $index.sft : $!";
while($line=<FILE>) {
chomp $line;
if($line=~/^rms/){
@info=split(/ /,$line);
push @rms,$index,$info[1];
%rms = @rms;
}
}
}
print "@rms\n";
print "file ==> value rms\n";
sub tmp {
$rms{$a}<=>$rms{$b};
}
foreach $key (sort tmp (keys (%rms))){
# print "$rms[$key] --> $key.sft -->> $rms{$key}\n";
print "$key.sft -->> $rms{$key}\n";
push @new,$key;
}
for ($i=1;$i<=$#new+1;++$i){
print "$i\_rank -->> $new[$i-1].sft\n";
system ("ln -s $new[$i-1].sft $i\_rank.sft");
}
# thanks
# regards
# xspirix
the below code works great but I would like to receive some comment
about its perl-ish style. (I am not new posting this kind of messagge,
but I want improve my style)
the problem is: I have several file, which they need to be ranked.
i.e.:
1.sft contains rms 1
2.sft contains rms 3
3.sft contains rms 2
4.sft contains rms 0.5
5.sft contains rms 3
........
and I would like to get at the end symbolic link, ranking the file bye
rms values:
rank_1.sft ---> 4.sft
rank_2.sft ---> 1.sft
rank_3.sft ---> 3.sft
rank_4.sft ---> 2.sft
rank_5.sft ---> 5.sft
.........
#!/usr/bin/perl
use warnings;
foreach my $index (1 .. $ARGV[0]){
open (FILE,"<$index.sft") || die "cannot open $index.sft : $!";
while($line=<FILE>) {
chomp $line;
if($line=~/^rms/){
@info=split(/ /,$line);
push @rms,$index,$info[1];
%rms = @rms;
}
}
}
print "@rms\n";
print "file ==> value rms\n";
sub tmp {
$rms{$a}<=>$rms{$b};
}
foreach $key (sort tmp (keys (%rms))){
# print "$rms[$key] --> $key.sft -->> $rms{$key}\n";
print "$key.sft -->> $rms{$key}\n";
push @new,$key;
}
for ($i=1;$i<=$#new+1;++$i){
print "$i\_rank -->> $new[$i-1].sft\n";
system ("ln -s $new[$i-1].sft $i\_rank.sft");
}
# thanks
# regards
# xspirix