Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
use warnings;
use File::Find;

my $srceDir = "//mnt/Share_Drive/Verizon PM&T/Capture Files/";
opendir(DIR, $srceDir) or die "Can't open $srceDir: $!";
my @files = (find -type f -newermt "12 Feb 2013", $srceDir);
closedir(DIR);

I can run the find command with the -newermt option in Linux just fine but when I put it in the perl script I got the errors below, could you help? Thanks

String found where operator expected at ./queryAlm.pl line 11, near "newermt "12 Feb 2013""
  (Do you need to predeclare newermt?)
syntax error at ./queryAlm.pl line 11, near "newermt "12 Feb 2013""
share|improve this question
2  
My 2 cents: it has nothing to do with find, it has to do with you quoting the command improperly. –  schaiba Feb 13 '13 at 17:25
    
@StephaneChazelas is right, the way your script is written you are trying to use the system's find instead of the perl module you previously imported. –  h3rrmiller Feb 13 '13 at 17:35

1 Answer 1

The File::Find perl module has little if any to do with the find command. See perldoc File::Find for how to use it.

As jordanm points out, you can use find2perl to help you write that perl code, but please note that find2perl only recognises the standard find syntax, so typically not GNU extensions like -newermt. You'll have to write the perl code by your self (call stat() for the file and compare the mtime with POSIX::mktime(0,0,0,12,2,113)).

To run the find command, you don't need the File::Find module, you can simply do:

my $srceDir = "//mnt/Share_Drive/Verizon PM&T/Capture Files/";
my @find_cmd = ("find", $srceDir, "-type", "f", "-newermt", "12 Feb 2013", "-print0");

open FIND, "-|", @find_cmd;
$/ = "\0";
my @files = <FIND>;
my $ret = close FIND or warn $! ?
    "Error closing find pipe: $!" :
    "find exited with non-zero exit status: $?";
share|improve this answer
2  
File::Find does come with a find2perl script that can generate perl code from your find command. –  jordanm Feb 13 '13 at 18:01
    
Actually, I would like to incorporate the unix command find into my perl script. I tried the following code: my $srceDir = "//mnt/Share_Drive/Verizon PM&T/Capture Files/"; my $find_cmd = 'find $srceDir -type f -newermt 2013-02-14 ! -newermt 2013-02-15'; open(FIND_FILE, "$find_cmd |"); while(<FIND_FILE>){ next if /^total/; print $_; } –  oanh Feb 15 '13 at 17:38
    
@oanh, please update your question (click edit under it) –  Stéphane Chazelas Feb 15 '13 at 17:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.