develooper Front page | perl.beginners | Postings from December 2002

Re: Using while ( -e $file )

Thread Previous
From:
Paul Johnson
Date:
December 26, 2002 15:45
Subject:
Re: Using while ( -e $file )
Message ID:
20021226234543.GB15140@pjcj.net
On Thu, Dec 26, 2002 at 04:31:30PM -0500, Scot wrote:

>  Trying to write a file monitor for temp files using a while loop. 
> The problem is that the file test does not seem to be re-evaulated 
> each loop. If I delete the file after the loop has started it 
> drops into the. SHRUNK test. I would think it would drop out of the 
> while loop.  
>  
> while ( -e $tfile ) { 
>       $SIZE = (-s "$TEMPFILE") /1024;
>       if ( $SIZE > $PSIZE ) {
>          $PSIZE="$SIZE";
>          print "$TEMPFILE Size = $SIZE Kb\n";
>       } elsif ( $SIZE < $PSIZE ) {
>          print "$TEMPFILE SHRUNK! from $PSIZE to $SIZE  Kb\n";
> 	}
> 	sleep(10); 
> }

Are $tfile and $TEMPFILE the same?  If so, just use one of the
variables.  If not, that's your problem.

And there is no need for the quotes around "$TEMPFILE" and "$SIZE".

And you probably want to set $PSIZE after the if statement, or in both
branches.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About