Since you are printing the data inside of the while-loop, it's printed before the count-value. You told the programm to do.
A solution is to gather the lines in an array, and print them after the while-loop, (of course unless you are reading more lines than fit into memory):
should do it. Note that I modified your loop, but provided a more proper solution below it.use File::Find; sub fetcher { my($ct, @data) = (0,()); if( $_ =~ /\.html?$/) { my $name = $File::Find::name; open ( F, $name ) or die "$!: $name\n"; #while( $line = <F> ) # { # for $i ($line =~ /stuffhere)/gi ) { # push(@data, "$i\n"); # gather the lines # $ct++; # } #} # since there is no requirement the lines need to match # why not local $/ = undef; @data = <F>; close F; } return($ct,\@data); } my ($ct, $data) = find( \&fetcher, "/directory" ); print @$data; print "\n\nTotal Count = $ct\n\n";
Since you are reading in html-files, I wonder if some CPAN-Module might be of interest to you.
regards,
tomte
Update:Modified the code to slurp the file in.
Update II:fixed the CPAN-link.
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
In reply to Re: Show count before data output
by Tomte
in thread Show count before data output
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |