in reply to Copying files between directories. How can I improve this code.

Some readability could be gained by some indentation. A run through perltidy wouldn't hurt.

Check the return of opendir. In checking it and chdir, include the $! variable in the error message.

Look into strict and warnings, when you're ready to try that again, it'll mostly involve just putting my in front of the first occurance of every variable, but try to understand the what and why of it.

There is no need to quote your arguments in copy().

Your basic method is sound, though.

  • Comment on Re: Copying files between directories. How can I improve this code.
  • Download Code

Replies are listed 'Best First'.
Re^2: Copying files between directories. How can I improve this code.
by richill (Monk) on Apr 22, 2006 at 00:26 UTC

    Is there anything in BBEdit that would do this. Can I link it to perltidy somehow? I'll find out now.

    I believe that my gives each varible a local scope. This stops bugs due to ambiguities.Correct me if I wrong please.

    Thanks for all your help BTW.

      Is there anything in BBEdit that would do this. Can I link it to perltidy somehow? I'll find out now.

      The easiest way would be to set it up as a unix filter. For example I have this:

      #! /usr/bin/perl # ~/Library/Application Support/BBEdit/ # Unix Support/Unix Filters/perltidy.pl use strict; use warnings; use Perl::Tidy; my @destination; Perl::Tidy::perltidy( source => [ <> ], destination => \@destination, ); print @destination;

      bound to ctrl-t on my BBEdit.