Re: problem about the perl code. thanks for any comments



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

.



Relevant Pages

  • Re: Google Groups: vote for Default quoting
    ... I made a mistake. ... I'm not missing posts by Sinan. ... the rule in the posting guidelines about counting to ten before posting ...
    (comp.lang.perl.misc)
  • Re: Moderating and netiquet whiners hurting interest in Perl
    ... > "Working with Duplicates in Perl to generate Unique ID" thread. ... > Sinan. ... All this hullabaloo got me to read that post, ... and promised to read the posting guidelines ...
    (comp.lang.perl.misc)
  • Re: Perl and waiting for execution of external program
    ... Something tells me you have made a delicious spaghetti and I do not have ... the inclination to go through it. ... You should read the posting guidelines ... Sinan. ...
    (comp.lang.perl.misc)
  • Re: Random String Generator
    ... "DMB" wrote in news:1110985110.078483.177460 ... Please provide context when you post. ... Please do read the posting guidelines for this group. ... Sinan ...
    (comp.lang.perl.misc)
  • Re: converting list to an array
    ... Sinan Unur" wrote in message ... have you read the posting guidelines yet. ... i have read, and trust me, the missing line was just an oversight on the cut ...
    (comp.lang.perl.misc)