prad_intel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Inititates -> Saints ,

In the process of development of a tool which recursively goes through all sub folders comparing files against same folder structure files , I ended up having a problem.

Please read the following for much details-

1) I take a folder from the user and mark it as main folder.

2)Assumes there are 2 other folders with same folder structure.

3)Compares the MD5 values of a file in main folder tree with a file in the same position as in main folder from the second and third folder.

4)prints certain values based on a logic developed by me.

Now for the problem -

1) When there exists a zip file in sub folder of main and similar or same zip files exists in sub folders of second and third folder , the result got is wrong because the file is not extracted and MD5 is digested for the zip file.

2)Here i used a zipdiff.exe tool( free tool of course )to finish of the work but that again is not able to do what I wanted it to.

I kindly request you all to look into this if you find it interesting and come out with a solution..

if($temp_var2 ne $temp_var1 and $temp_var3 ne $temp_var2 and $temp_var +2!~/FNF/ and $temp_var3!~/FNF/ and $temp_var3 ne $temp_var1){ if(($file1 eq $file2) =~(/.zip/i)){ system "c:\\zipdiff.exe $file1 $file2> +d:\\zipdiff.tmp"; open (ZDF, "<d:\\zipdiff.tmp"); $zipdiffresult = (<ZDF>); close (ZDF); #DeleteFile ("c:\\bin\\zipdiff.tmp"); if($zipdiffresult!~/different/){ printf LOG"2";$v1=1;} else{printf LOG"5";$v1=1;} } }
Here $temp_var1,$temp_var2,$temp_var3 are the MD5 values of a file with same name existing in main , second and third folders respectively.

$v1 is a flag , which i am setting to find any error.

Thanks a ton in advance , as I believe , there are pearled people here..

Prad

Replies are listed 'Best First'.
Re: Zipped problem !
by demerphq (Chancellor) on Feb 04, 2005 at 09:15 UTC

    Ok, im not really sure what you are asking, and its a little hard to tell whats going on here. I suggest you rework your code a little and try to absorb some advice:

    Here $temp_var1,$temp_var2,$temp_var3 are the MD5 values of a file with same name existing in main , second and third folders respectively

    Ok, id like to ask you some questions: if you can write the above line then why are the variables so poorly named? Why aren't they named $md5_main, $md5_second, and $md5_third, or even possibly @md5[0..2] Next you get an external process to pipe to a file that you then open and read, why don't you just get the external process to perl using open and then read its output directly? Other issues come up, whats $v1? Whats $file1 and $file2? What do you think if(($file1 eq $file2) =~(/.zip/i)){ does?

    A lot of this is just sloppyness, $v1 is an error flag? And I need to read your text to see that?

    Lastly your indentation is pretty bad. You need to clean it up. Go and have a look at any of the posted code by folks like tye or tilly or dws or theorbtwo or BrowserUk or so on and youll see that they all use some form of consistant easy to read indentation and style. Pick the features of them all you like and then use it rigiorously. The indentation of a code gives it life and form making it flow like a poem, minimizing line lengths and using descriptive variable names makes it easier to userstand. Imagine a play like Hamlet where every characters name was replaced by $temp_char, $royal1,$royal2, $soldier, etc. Would you have any idea what was going on past the first or second act? Would the actors even be able to keep their own lines straight?

    The point here, is that im betting that if you actually reworked this code so it was readable the "error" would magically disappear. It would just be totally obvious as you reworked things what was going on and why.

    Please dont be discouraged by this reply. But please do try to learn from it. Good luck.

    ---
    demerphq

      Hi demerphq,

      I am not discouraged about your comments,infact I have taken it positively.

      The best way to learn a thing and become best is to have a best teacher ( or monk ) and tats the reason i joined this group.

      All comments are welcomed.

      I have learnt a lot from perlmonks.org and I am doing better day by day and I am sure within a few months I shall be competitive to bart , corion and others

      I shall take your comments and integrate it and shall re-post once things are per your expectation.

      Every bubble grows to finally burst but knowledge is the only bubble which gets stability as it grows...

      I am a pupil to all those monks and saints here

      Prad

Re: Zipped problem !
by castaway (Parson) on Feb 04, 2005 at 09:06 UTC
    prad, some suggestions:
    1. Give those temp vars meaningful names.. What are they? Found files? folders? Ah, MD5s.. then call them $tempMD5_1 or something..
    2. Don't copy code unless you know what it does. I get the feeling you copied that if(($file1 eq $file2) =~(/.zip/i)){ or similar from somewhere.
    3. Try to explain yourself in words what the code does
    4. Use debugging prints. Print out what $file1 is, what $file2 is, what ($file1 eq $file2) is, and finally the entire expression in the if. Then you'll see why it doesnt work.

    C.

Re: Zipped problem !
by chb (Deacon) on Feb 04, 2005 at 07:47 UTC
    What is
    if(($file1 eq $file2) =~(/.zip/i)){ ... }
    supposed to do? ($file1 eq $file2) returns a boolean which is then matched against a regexp?
      checks wether the file1 and file 2 are have the same file name and further check wether it has a .zip extension..

      Sorry if its a bad logic..

        ($file1 eq $file2) will evaluate to 1 (if the filenames are indeed equal) or the empty string (if the filenames differ). None of these values will ever match /.zip/i. (BTW you have to quote the dot in the regexp if you want to match a literal dot).