Sorry Monks ,

I am totally new to this kind of a technical group and am getting aware of how to list out the problems.

Thanks to all those who have identified my mistakes in defining the problem.

the code is as follows , I hope now people can easily test it out and bring the best to me.

</p> #!/usr/bin/perl -w use Strict; use File::Stat; use Digest::MD5; print "Enter the Path where all the data files are available:\t"; $sourcedir= <STDIN>; chomp($sourcedir); open(LOG ,">>D:\\prad\\log1.csv"); #$workbook = Spreadsheet::WriteExcel->LOG('D:\prad\log1.csv'); print LOG "Report Ver - 0.1\n"; print LOG"_______________________________\n"; print LOG "\nFilename,Md5sum(oneof),Size,Md5Sum(oneofcmd_cln),Size,Md5 +Sum(oneofgsd_cln),Size"; print LOG"\n___________________________________________\n"; list_recursively("$sourcedir\\oneof"); exit; ###################################################################### +########## # Subroutine ###################################################################### +########## # list_recursively # # list the contents of a directory, # recursively listing the contents of any subdirectories # sub list_recursively { my($directory) = @_; my @files = ( ); # Open the directory unless(opendir(DIRECTORY, $directory)) { print "Cannot open directory $directory!\n"; exit; } # Read the directory, ignoring special entries "." and ".." @files = grep (!/^\.\.?$/, readdir(DIRECTORY)); closedir(DIRECTORY); # If file, print its name # If directory, recursively print its contents # Notice that we need to prepend the directory name! foreach my $file (@files) { # If the directory entry is a regular file if (-f "$directory/$file") { $filepath="$directory"; $filepath2=$filepath; $filepath2=~s/oneof/oneofcmd_cln/; $filepath3=$filepath; $filepath3=~s/oneof/oneofgsd_cln/; #Finding the size of the file #digesting open(FILE ,"<$filepath\\$file"); binmode (FILE); $file_size="$filepath\\$file"; @st = stat($file_size) or die "No $file: $!"; $digest = Digest::MD5->new->addfile(*FILE)->hexdigest; #print file name in Log file print LOG "\n$filepath\\$file"; printf LOG",%s,%s",$digest,$st[7]; close(FILE); if(open(FILE, "<$filepath2\\$file")) { #print LOG "in MD2"; binmode (FILE); $file_size="$filepath2\\$file"; @st = stat($file_size) or die "No $file: $!"; $digest = Digest::MD5->new->addfile(*FILE)->hexdigest; printf LOG",%s,%s",$digest,$st[7]; close(FILE); } else{ print LOG",Null,";} if(open(FILE, "<$filepath3\\$file")) { #print LOG "in MD3"; binmode (FILE); $file_size="$filepath3\\$file"; @st = stat($file_size) or die "No $file: $!"; $digest = Digest::MD5->new->addfile(*FILE)->hexdigest; #print file name in Log file #print LOG "$filepath3\\$file"; printf LOG",%s,%s",$digest,$st[7]; #here i need to include a formula into the csv file at the #end of eac +h line. close(FILE); } else{ print LOG",Null";} # If the directory entry is a subdirectory }elsif( -d "$directory/$file") { # Here is the recursive call to this subroutine print LOG"\nFolder - $directory\\$file \n"; print LOG"----------------------------------\n"; list_recursively("$directory\\$file"); } } } ###################################################################### +##########

Any improvements in the code would be a great addition. Sorry , Thanks and Regards

Pradeep.S

In reply to Re: Subroutine speed by prad_intel
in thread Subroutine speed by prad_intel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.