Phoenix.pm: Code problem

Giffin Ron-P08295 Ron.Giffin at motorola.com
Tue Oct 12 18:00:19 CDT 1999


Kevin,
I am using some system calls inside Perl and sometimes
encountering unexpected row (record) sizes, therefore
I wanted to write a script to see how Unix sees the line
and how Perl sees the line.  When wc is executed the file
size seems to be 0 - doesn't make sense to me.

  -- Ron

-----Original Message-----
From: Kevin Buettner [mailto:kev at primenet.com]
Sent: Tuesday, October 12, 1999 3:39 PM
To: phoenix-pm-list at happyfunball.pm.org
Subject: Re: Phoenix.pm: Code problem


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