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?
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]