Thank you for the response. I must confess that I have been reading the
Perldocs, but I am having some logic troubles, difficult to understand how
to use File::Find. I tried using the push routine, but that listed all
files instead of only listing all files that have "domain.com". If I change
code back to print("$name\n"); It will list only files found that meet
grep criteria. I am guessing I am not following the logic very well. I
would much rather do the whole thing in straight perl, but I need the find
to recursively search directories and not cross filesystems or links, as
well as tell me the names and locations of files. To use straight perl,
seemed like a lot of nested loops, but that could also be due to the fact
that I am still learning. To cleanup the routine exec, I am not sure how to
do it, and have it do what I want. Eventually, I need the results in an
array, so I can then manipulate those items in the array. I do not need
those files that do not meet the grep requirement.
I apologize for my slowness, but any illumination you provide will be
greatly appreciated.
Thanks
Greg
On Tue, Jul 31, 2001 at 03:38:17PM -0700, Greg Tomczyk wrote:
> I was wondering if some one could assist me in something I am sure is
> simple for most. I am utilizing find2perl utility and implemented it into
a
> perl script. However I would like to have the results of the find stored
> into an array.
find2perl was a starting point, now you need to read and understand how
File::Find::find works, and how the wanted subroutine interacts with it.
See perldoc File::Find.
[snip]
> sub wanted {
> (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
> &exec(0, 'grep','-q','domain.com','{}') &&
> print("$name\n");
> #@filelist=$name;
> #print ("Test to see if $name print\n");
> }
You almost had it, except "@filelist = $name" assigns $name to @filelist,
clearing out any other elements already there. You want push, as in
"push(@filelist, $name)".
> sub exec {
> local($ok, @cmd) = @_;
> foreach $word (@cmd) {
> $word =~ s#{}#$name#g;
> }
> if ($ok) {
> local($old) = select(STDOUT);
> $| = 1;
> print "@cmd";
> select($old);
> return 0 unless <STDIN> =~ /^y/;
> }
> chdir $cwd; # sigh
> system @cmd;
> chdir $dir;
> return !$?;
> }
If you're going to be using this code in production you should replace this
subroutine, as well as the usage of this subroutine in wanted(), with a
trimmed down one that does nothing but system and checks the return value.
There is generalized code here that makes sense for one-off find2perl
usage,
but not for code that's being used and maintained on a production basis.
Also, if you want it to be portable you should do the grep in Perl, rather
than executing an external command.
> wanted;
>How did this end up down here?
That was a copy paste thing onto mail. In my script I just call the routine
wanted..
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]