in reply to Re^4: Duplicates in Win32::DirSize
in thread Duplicates in Win32::DirSize
Is there any way you can provide your data file? If it's very large, put it on your scratchpad rather than here. Also, please give the "long error message" you are getting so I can try to see what's going on.
It looks like you're using a LOT of global variables. This can be bad, as you may inadvertently change the global in another function. Instead, try passing variables between your subroutines and declaring scopes by using my. Also, some more code efficiency:
1. You can avoid using a bunch of escape characters by using alternative characters for your regexes. It will sometimes look cleaner and be much easier to see what it is you're trying to do.
$dest =~ s/\//\\/g; # Rewritten: $dest =~ s#/#\\#g; # Singular character $dest =~ s{/}{\\}g; # Paired characters
There are a bunch of other characters you can use here. Don't worry, the # won't be seen as a comment.
2. Don't bother making a copy of an array before sorting it. The sort function will return the sorted array without changing the original.
@sortedarraydirectory = @arraydirectory; @sortedarraydirectory = sort @sortedarraydirectory # Change to 1 command: @sortedarraydirectory = sort @arraydirectory;
I also learned Perl on my own, with some limited help from a guy at work (heck, I'm still learning it!). I highly suggest you look into O'Reilly's Learning Perl, as it's a very well-written resource that will teach you the essentials. Progamming Perl is also a valuable resource, but moreso after you are already familiar with the language.
|
|---|