On Thu, 28 Mar 2002, Bob Showalter wrote: > > From: eric-perl@pretorious.net [mailto:eric-perl@pretorious.net] > > Thanks, Bob! After reading the IO::Handle man page, I decided > > to distill this approach a bit further: > > > > print F if fileno(F); > > Of course, that's even simpler! Just to be nitpicky, the test maybe > should be > > defined(fileno(F)) > > Since 0 is a valid file number (STDIN). So, technically, I should be testing for "definedness" instead of "truth". i.e., From `perldoc -f fileno`: Returns the file descriptor for a filehandle, or undefined if the filehandle is not open. > If you're just going to do the test on the print statement, it's > not accomplishing all that much, since the print() will silently > fail if the file isn't open. But a test like this would be useful > if you want to avoid doing a lengthy operation to generate the > data to be printed. Printing to a non-existant filehandle (while using the -w switch) generates a warning message: Filehandle main::FOO never opened at... -- Eric P. Los Gatos, CAThread Previous | Thread Next