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

This prints output to my screen. I need it to print all the output ($ct and $i) to a file. Each time I run this I need it to overwrite the file and give me the new results only in the file. Please advise How I get this to output to a file??
use File::Find; my $ct = 0; sub subrout { if( $_ =~ /\.pl$/) { while( $line = <F> ) { for $i ($line =~ /data)/gi ) { print "$i\n"; $ct++; } } close F; } } find( \&subrout, "/pathOne" ); print "\n$ct\n";

Replies are listed 'Best First'.
Re: Output data to a file
by broquaint (Abbot) on Jun 23, 2003 at 15:16 UTC
    To save re-working your existing code just use select and open
    use File::Find; open(FH, ">your_output_file") or die("ack - $!"); select(FH); ## rest of your code here
    That assumes that is the entirety of your script, and if not remember to add a select(STDOUT) and close(FH) after you've finished outputting to your file. See. the select and open docs for more info.
    HTH

    _________
    broquaint

      Thanks!