Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: if -s clause on a FILEHANDLE

by Fletch (Bishop)
on Jun 08, 2004 at 14:06 UTC ( #362340=note: print w/replies, xml ) Need Help??

in reply to if -s clause on a FILEHANDLE

Erm, why not just if( @ftapes ) { ... }?

Update: Also note that since you call select OUT and never re-select the old handle that your print will go to the OUT handle. You may want to use the common select( (select(OUT),$|=1)[0] ) idiom instead.

Replies are listed 'Best First'.
Re^2: if -s clause on a FILEHANDLE
by drock (Beadle) on Jun 08, 2004 at 14:24 UTC
    what exactly is
    select( (select(OUT),$|=1)[0] )
    saying? I still want to state
    if ( -s "@ftapes" ) { ..... }
    right? not just if ( "@ftapes" )

      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);

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362340]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2023-12-01 10:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found