> I have the following find/grep line running just fine from a
> telnet prompt on the server. I'm trying to include this line
> into a web app using CFEXECUTE (ColdFusion) but can't get it
> to work. I know that a compiled perl script would work since
> I'm already using some previously written ones.
>
> How could I do the following in Perl? I'm searing the
> directory d:\mywork and all sub-directories within for all
> the files with a .txt file extension and within those files
> for the match of "000;"
>
> find D:\mywork -name '*.txt' -exec grep '000;' '{}' \; -print"
You can use find2perl (installed with perl) to change your find command to
perl's equivalent.
The following returns me the perl code.
$-> find2perl work -name '*.txt' -exec grep '000;' '{}' \; -print
#! /depot/perl-5.6.0/bin/perl -w
eval 'exec /depot/perl-5.6.0/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, 'work');
exit;
sub wanted {
/^.*\.txt\z/s &&
&doexec(0, 'grep','000;','{}') &&
print("$name\n");
}
BEGIN {
require Cwd;
my $cwd = Cwd::cwd();
}
sub doexec {
my $ok = shift;
for my $word (@_)
{ $word =~ s#{}#$name#g }
if ($ok) {
my $old = select(STDOUT);
$| = 1;
print "@_";
select($old);
return 0 unless <STDIN> =~ /^y/;
}
chdir $cwd; #sigh
system @_;
chdir $File::Find::dir;
return !$?;
}
--Ankur
If the automobile had followed the same development cycle as the computer, a
Rolls-Royce would today cost $100, get a million miles per gallon, and
explode once a year, killing everyone inside. - Robert X. Cringely
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>