Hello Listers.
Hello,
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.
Your regular expression is matching \w+\.\w+ however file names can contain characters that are not included in the \w character class. It would be better to use the File::Basename module to extract the file name from the path.
use warnings; use strict; use File::Copy; use File::Basename;
while ( glob '//xxxxxx/code/*.*' ) { my $filename = basename( $_ ); next unless $filename =~ /[^.]\.[^.]/; copy( $_, "c:/code/$filename" ) or die "Copy failed: $!"; } }
__END__
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>