Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello I am a Perl newbie, I have been trying to get this script to simply output the search results to a text file. I am stuck... Can any body give me some pointers so that I can move onto my next perl problem?
use strict; use File::Find (); use Win32::FileSecurity; #! D:\Perl\bin\perl.exe -w eval 'exec D:\Perl\bin\perl.exe -S $0 ${1+"$@"}' if 0; #$running_under_some_shell #! D:\Apps\codemagic\lang\perl\bin\perl.exe -w # eval 'exec D:\Apps\codemagic\lang\perl\bin\perl.exe -S $0 ${1+"$@ +"}' # if 0; #$running_under_some_shell open(OUT, ">> output.txt") || die "can't open output.txt: $!"; # Get full date for report. my $Date = localtime (time); #print OUTPUTFILE "----------Open log $Date ----------\n"; # 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 print " Access DB's Modified between now and 6 Months ago\n"; File::Find::find({wanted => \&wanted}, '\\\\lindoze /c$'); close(OUT); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); /^.*\.bat\z/s && (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && (int(-M _) > 0) && (int(-M _) < 180) && print("$name\n"); }
Thanks,

PerlNOOB

Replies are listed 'Best First'.
Re: Write output of File::Find::find({wanted => \&wanted}, to a file?
by duff (Parson) on May 21, 2004 at 18:08 UTC
    There are several ways to achieve the desired result.

    One way is to just use redirection and run you program from the command line: program >> output.txt.

    Another way would be to change your print statement such that it outputs to your file handle:  print(OUT "$name\n");

    Yet another way is to make the OUT filehandle the default using select immediately before you call File::Find::find().

    Take your pick