http://qs321.pair.com?node_id=1106157

bbb has asked for the wisdom of the Perl Monks concerning the following question:

Greetings perl masters!

I am a beginner with perl and I would like to seek your help regarding my script.

My script should find a string within the files then copy it to a directory. When I test copy within my local dirs, the script works. But when I tried to copy from a source dir (which is linux), the script doesn't work.

Please help! Thanks!

#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Copy; my $target = 'C:\target'; my $pattern = 'SearchWord'; open my $copylog, '>', 'C:\target\copylog.csv' or die "Error opening c +opylog.csv: $!\n"; open STDERR, ">>&=", $copylog or die "Can't redirect STDERR"; $copylog->autoflush(1); find( sub { if (-f) { open my $file, '<', $File::Find::name or die "Error opening fi +le: $!\n"; while (my $line = <$file>) { if($line =~ m/$pattern/ig) { copy ($File::Find::name, $target) or die "Copy fai +led: $!"; print $copylog $_ . "," . $pattern . "\n"; } } close $file; } },glob ('Z:\Linux\site'));

Update:

I had used Loops sample and it worked:

use strict; use warnings; use File::Find; use File::Copy; use autodie; my $log = q(C:\target\copylog.csv); my $target = q(C:\target); my $pattern = qr(SearchWord); close *STDERR; open *STDERR, '>', $log; find( sub { if (-f) { open my $file, '<', $_; while (my $line = <$file>) { if($line =~ m/$pattern/ig) { copy ($_, $target); warn "$_, $pattern\n"; last; } } close $file; } }, glob ('Z:\Linux\site') );

It seems that copying from a drive with other platform should not be an issue. It is a matter of faulty script that does not make it work. Again, thank you guys for the time spent in dealing with my issue. All pointers are taken and I will apply it in my scripting.

Thanks and best regards!