Phoenix.pm: Code problem

Kevin Buettner kev at primenet.com
Tue Oct 12 17:38:34 CDT 1999


On Oct 12,  3:20pm, Giffin Ron-P08295 wrote:

> Ok...  My fear of being a dummy is overpowered by my need to
> finish this script.  $in_file contains 44 word columns separated
> by tabs.
> 
>     open ( IN_FILE, $in_file ) || die ........
>     open ( OUT_FILE, "> $out_file" ) || die .......
>     while ( <IN_FILE> )
>         {
>         print OUT_FILE $_ ;
>         $size = `wc -w $out_file | tr -s " " | cut -f1 -d " "` ;
>         print "Unix word count = $size\n" ;
>         }
>     close ....
>     close ....
> 
> $size is always 0 ---- What's wrong with this ( bet I going to be
> embarrassed )

How big are the files that you're trying it on?  My guess is that
the buffer is not getting flushed.  You might try doing

    OUT_FILE->autoflush(1);

after opening it.  (You'll also have to add a "use FileHandle;" line.)

BTW, there are better ways of keeping track of the number of words
written out.  I would just let perl count them for you; e.g, try doing

	$size += split;

Kevin

-- 
Kevin Buettner
kev at primenet.com, kevinb at cygnus.com



More information about the Phoenix-pm mailing list