in reply to File Search

Ok, the shell solutions are good, but if you really want to use Perl have a look on this:
use File::Find; find(\&wanted, './'); sub wanted { return unless /\.out$/; open F, '<', $_ or return; while (defined (my $line = <F>)) { print "ACTION!" if $line =~ /error/; } close F; }
#1 => File::Find is the module for searching a directory tree. Have a look at the POD to find out more.

#2 => If the files are big, you may want to think about optimizing, but for small files above is enough.

#3 => There are multiple modules on CPAN to do this cleanly. Search for sendmal or smtp and choose what fits your needs.

#4 => That's hard. You may want to look for a module like ACME::NOP or CORE::return, but I'm really unsure if they do enough nothing... ;-))


Update: And don't try to look at a Perl Monks Preview after to much Irish Coffee---you won't see the missing <p>s...

Search, Ask, Know

Replies are listed 'Best First'.
Re: Re: File Search
by mikevanhoff (Acolyte) on Oct 23, 2003 at 16:48 UTC
    Thanks for guidenance. I have it working in my test environment. However, I know in my production environment I will be encountering files and directories from previous process runs. I need to be able to only select those directories/Files that have been created on the current date, and if possible between a defined start and end time. Any suggestions? Thanks in Advance.
      That's fairly easy. Just see perldoc -f stat. You can get all possible data about a file, including the last change timestamp.

      Please note, you cannot usually get the creation time, because it is not recorded by all file/operating systems.

      sub wanted { return unless /\.out$/; my $ctime = (stat $_)[9]; if ($ctime < time()-(2*60*60)) { print "$_ is older than 2 hours.\n"; } elsif ($ctime > time()) { print "$_ has used a time machine to get here!\n"; } else { un#link $_; print "I hate new files.\n"; } }

      Search, Ask, Know