Re: problem about the perl code. thanks for any comments
- From: "yezi" <ye_line@xxxxxxxxxxx>
- Date: 30 Aug 2005 14:15:04 -0700
Hi: Thanks for Sinan 's help. the following is the whole code. pls
check.
#!/usr/bin/perl -w
# DT value=$DT, site name=$site
my($DT,$site);
my($i,$j);
my($serial,$entropy);
my(@parts,@part1,@files);
my($file);
my($line);
$DT=25;
$site="download.microsoft.com";
for ($i=0;$i<=(2*$DT);$i++) {$RD[$i]=0;} #initiat the array of RD[]
#write the title of each column
print "Serial\t";
for($i=-$DT;$i<=$DT;$i++) {print "RD[$i]\t";}
print "Entrophy\n";
#analysis the RD file by serial
opendir DIR,"." or die "Cannot open current directory: $!";
@files = readdir DIR;
foreach $file (@files)
{
if ($file =~ /\.RD/)
{
# print "$file";
open myRDfile,$file or die "Error:Could not open $file ";
while($line=<myRDfile>){
chomp($line);
@parts = split(/ /,$line);
if ($parts[0] !~ /Entropy/)
{ for ($j=-$DT;$j<=$DT;$j++)
{ if($parts[0] =~ /RD[$j]/) { $RD[($j+$DT)] =
$parts[2];} } # mapping
}
else {$entropy =$parts[2];}
else {$entropy =$parts[2];}
}
close myRDfile;
#output the RD metric to default
@part1= split(/\./,$file);
print "$part1[0]\t";
for($i=0;$i<=(2*$DT);$i++) {print "$RD[$i]\t";}
print"$entropy\n";
}
}
A. Sinan Unur wrote:
> "yezi" <ye_line@xxxxxxxxxxx> wrote in news:1125434263.574194.118650
> @z14g2000cwz.googlegroups.com:
>
> > Hi all: the following is my program , Do not know why it can not
> > open file (*.RD ) in the current directory. Thanks for any comments.
>
> Please post code that others can run by just copying and pasting. That
> means no line numbers.
>
> use strict;
> use warnings;
>
> missing.
>
> > 24 opendir DIR,".";
>
> Always, always check the return value of system calls
>
> opendir my $current_dir, '.'
> or die "Cannot open current directory: $!";
>
> > 25 @files = readdir DIR;
> > 26 foreach $file (@files)
> > 27 {
> > 28 if ($file =~ /\.RD/)
> > 29 {
>
> my @files = grep { /\.RD$/ } readdir $current_dir;
> closedir $current_dir
> or die "Cannot close current directory: $!";
>
> for my $file (@files) {
>
> > 30 $sitename=chomp($file);
>
> 1. Why are you chomping $file?
> 2. What do you thing chomp returns?
>
> In all likelihood, $sitename is now set to 0.
>
> Please read the posting guidelines for this group to lern how you can
> help yourself, and help others help you.
>
> Sinan
>
> --
> A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
> (reverse each component and remove .invalid for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.
- Follow-Ups:
- Re: problem about the perl code. thanks for any comments
- From: John W. Krahn
- Re: problem about the perl code. thanks for any comments
- References:
- problem about the perl code. thanks for any comments
- From: yezi
- Re: problem about the perl code. thanks for any comments
- From: A. Sinan Unur
- problem about the perl code. thanks for any comments
- Prev by Date: Re: problem about the perl code. thanks for any comments
- Next by Date: Re: Perldoc on the web
- Previous by thread: Re: problem about the perl code. thanks for any comments
- Next by thread: Re: problem about the perl code. thanks for any comments
- Index(es):
Relevant Pages
|