[ Please do not top-post. TIA ]
[EMAIL PROTECTED] wrote:
From: Denham Eva <[EMAIL PROTECTED]>
Please I am a beginner.
I am making tentative steps to creating a script which will keep my
Notebook and Workstation at work in sync.
My first attempt is just to copy the files from the one to local.
Here is my script - it works, but I suspect there should be a better way
to do this "More Perl Correct" so to speak.
use warnings; use strict; use File::Copy;
while(defined(my $filename=glob("//xxxxxx/code/*.*"))) { if ($filename =~ m/(\w+)\.(\w+)/){ my $main = $1; my $ext = $2; copy ("$filename", "c:/code/$main.$ext"); } }
I would especially appreciate pointers on the regex, is there a better way to do this? All pointers will be appreciated.
Denham, As usual with Perl, one can express them self's as they wish. There really is no beter way to do any task, unless you have specific specifications/standards. Here is an alternative, using 'split' function.
#!PERL -w use warnings;
You probably shouldn't use both " -w" and "use warnings;". Read the perllexwarn man page for an explanation of the difference between the two.
perldoc perllexwarn
use strict; use File::Copy;
my @files=glob('C:\pie\bar\*.*');
There is no *good* reason to use backslashes.
my ($file,$debug);
for $file ( @files ){
You should declare $file here as its contents are only visible inside the for loop.
for my $file ( @files ) {
no strict;
There is *NO* *GOOD* reason to turn off strict!
next if -d $file; # skip directorys print "$file \t" if $debug; local ($main,$ext) = split /\./,$file;
You should only use local() if you are stuck in Perl4 (ick!) or you need to localize one of perl's built-in variables.
print "$main:$ext\n" if $debug copy ("$file, "c:/code/$main.$ext");
^ Syntax error, unmatched quote.
}
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>