in reply to Re: if -s clause on a FILEHANDLE
in thread if -s clause on a FILEHANDLE

what exactly is
select( (select(OUT),$|=1)[0] )
saying? I still want to state
if ( -s "@ftapes" ) { ..... }
right? not just if ( "@ftapes" )

Replies are listed 'Best First'.
Re^3: if -s clause on a FILEHANDLE
by Fletch (Bishop) on Jun 08, 2004 at 14:42 UTC

    The select stuff is a hackish shortcut from the dawn of time (or at lest the perl4 days) to set autoflush on a handle without changing the current default output handle afterwards. The chunk inside the inner parens is a list consisting of the previous default output handle (what you were getting with my $svsel = select OUT;) and then setting $| on the default output handle (which is then OUT since the select executes first). The list value is subscripted to get just the first element (the old saved handle) and that's passed to select to reset the default output handle.

    And no, you don't want  -s "@ftapes". -s gets the size of a file (either by name or for an already opened filehandle). Yours would attempt to find the size of a file named after the contents of @ftapes joined by $,. Using an array in a scalar context evaluates to the number of items in the array; if you found any items then @ftapes will have a non-zero number of elements and evaluate to a true boolean value.

      Is there a ideal way to "touch" a file instead of opening a file then >$foo it? for example,
      my $foo="/tmp/ftapes_runfile"; open (RUNFILE, ">$foo") || die "could not open runfile: $!;" close (RUNFILE);