On Fri, Dec 30, 2011 at 12:33 AM, Jonathan Harris
<jtnhar...@googlemail.com>wrote:

>
>
> On Thu, Dec 29, 2011 at 6:39 PM, John W. Krahn <jwkr...@shaw.ca> wrote:
>
>> Jonathan Harris wrote:
>>
>>>
>>> Hi Igor
>>>
>>> Many thanks for your response
>>>
>>> I have started reviewing the things you said
>>> There are some silly mistakes in there - eg not using closedir
>>> It's a good lesson in script vigilance
>>>
>>> I found the part about opening the file handle particularly interesting
>>> I had no idea that
>>>
>>> open my $wr_fh, '>', File::Spec->catfile($path, $dircontents, '.md5') or
>>> die $!, $/
>>>
>>> was possible
>>>
>>> Now it's time to sit down and digest all this......and rewrite the script
>>> to make it better!
>>>
>>
>> Igor made a lot of good points.  Here are my two cents worth.  You are
>> using the File::Find module to traverse the file system and add new files
>> along the way.  This _may_ cause problems on some file systems. It would
>> probably be better to get a list of applicable files first and then use
>> that list to create your new files.  And you should have some way to handle
>> the situation where a file exists that already has an '.md5' file or an
>> '.md5' file exists with no corresponding plain file.
>>
>>
>>
>> John
>> --
>> Any intelligent fool can make things bigger and
>> more complex... It takes a touch of genius -
>> and a lot of courage to move in the opposite
>> direction.                   -- Albert Einstein
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
> Hi John
>
> Thanks for your 2 cents
>
> I hadn't considered that the module wouldn't be portable
> If that is the case, then maybe it would be best to
> ditch File::Find altogether?
> Have you had experience with the module causing issues on certain systems?
>
> It would be a shame, as I've just got it working! - Thanks to Igor, I no
> longer use the unnecessary dir handles!
>
> I agree that it may be worth examining the directory for existing .md5
> files and skipping them
> I'll look in to adding that in to the code
>
> All the best and thanks for your help
>
> Jonathan
>

Hi All

Final question for Igor

I tried to use your suggestion

open my $wr_fh, '>', File::Spec->catfile($path, $dircontents, '.md5') or
die $!, $/


but it returned an error on the command line:

'Not a directory'

At which point the program dies (which is what it is supposed to do!)

I used it inside the loop - sorry to bug you for clarification


####


if ($dircontents=~/^\./ || -d $dircontents) {

next;

    }


This is also to avoid the file .DS_Store


#####


FInally, I was advised by a C programmer to declare all variables at the
start of a program to avoid memory issues

Is this not necessary in Perl?


The rest of it is going really well - hope to post new and improved code
soon!

Reply via email to