ok I can take some blame!  : )  I made some changes and I am still not 
getting the print message.


## Set pragmas

        use strict;

        my $foreigntapes="/usr/local/log/foreign_tapes.log";
        delete $ENV{'IFS'};
        local $ENV{'PATH'} = 
"/usr/epoch/bin:/usr/epoch/EB/bin:/usr/bin:/usr/sbin:/bin:/sbin";

        open (OUT, ">$foreigntapes") || die "could not open file:$!";
        my @ftapes = grep s/^barcode=//, `evmvol -w label_state=1`;
        my $svsel = select; select OUT; $| = 1;
        print OUT "@ftapes";
               if ( -s OUT ) {
                             print "file is greater than 0 bytes \n";
                       }





Bob Showalter <[EMAIL PROTECTED]>
06/08/2004 09:45 AM

 
        To:     "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
        cc: 
        Subject:        RE: if -s clause


[EMAIL PROTECTED] wrote:
> I have tried all three methods.... if -s OUT, if -f $filename and if
> -s @arrayname with no evail.????
> I did make a test.pl file so that I am just testing whether the file
> is greater than 0 bytes.  Here is the code.
> autoflush is turned on.  Is this the correct spot for this?

1. Autoflush is not turned on for the handle OUT. To do that, you would 
need
to use:

   my $svsel = select; select OUT; $| = 1;

or, better yet:

   use IO::Handle;
   OUT->autoflush(1);


2. Because of buffering, even though you have printed to OUT, the data has
not actually been written to disk yet (still in the stdio buffers), so

3. -s OUT returns 0 (which is true)

The proper test for your program is

   if (@ftapes)

This evaluates the array in boolean (scalar) context, which gives the 
number
of elements in the array. If the array is not empty, the test is true,
regardless of what's going on with the file.

> 
> Is it this tedious to test if a file is greater than 0 bytes????

Nope. You are testing, and the file is 0 bytes.

> I thought perl is supposed to be this great language for UNIX and C
> people???

Your algorithim is the problem, not Perl.


Reply via email to