# Copying files from One PC to another. - PERL Beginners

Hello Listers. 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("///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, ... 1. ## Copying files from One PC to another. Hello Listers. 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("///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.

Many Thanks

Denham

Denham Guest

2. ## Re: Copying files from One PC to another.

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;
use strict;
use File::Copy;

my files=glob('C:\pie\bar\*.*');
my ($file,$debug);

for $file ( files ){ no strict; next if -d$file; # skip directorys
print "$file \t" if$debug;
local ($main,$ext) = split /\./,$file; print "$main:$ext\n" if$debug
copy( $_, "c:/code/$filename" ) or die "Copy failed: $!"; } } __END__ John -- use Perl; program fulfillment John Guest 4. ## Re: Copying files from One PC to another. [ Please do not top-post. TIA ] net wrote: > 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;[/ref] 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 There is no *good* reason to use backslashes. You should declare$file here as its contents are only visible inside the for
loop.

for my \$file ( files ) {

There is *NO* *GOOD* reason to turn off strict!

You should only use local() if you are stuck in Perl4 (ick!) or you need to
localize one of perl's built-in variables.

^
Syntax error, unmatched quote.

John
--
use Perl;
program
fulfillment
John Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•