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!


In reply to [Solved] Cannot copy files from linux shared to windows by bbb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.