I think in order for that to work, you might have to put use vars($opt_n) at the top of your script. To be honest, I don't use Getopts that much, maybe someone else would have a better idea?
-----Original Message----- From: Agustin Rivera [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 27, 2002 1:46 PM To: Timothy Johnson; Beginners Perl Mailing List Subject: Re: Testing for filehandles How would that work with use strict;? I tried it once and when I declared my $opt_n before using getopts, it wouldn't work. Agustin Rivera Webmaster, Pollstar.com http://www.pollstar.com ----- Original Message ----- From: "Timothy Johnson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "Beginners Perl Mailing List" <[EMAIL PROTECTED]> Sent: Wednesday, March 27, 2002 1:32 PM Subject: RE: Testing for filehandles > > You'd probably have better luck testing for the open() command's success > > use Getopts::Std; > getopts("n"); > if($opt_n){ > open(OPT_LOG,">/tmp/foo.txt") || die "Could not open foo.txt!\n"; > } > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 27, 2002 12:18 PM > To: Beginners Perl Mailing List > Subject: Testing for filehandles > > > Hello, All: > > I've looked around for an answer to this (The Camel Book, The Ram Book, > perldoc, google.com, etc.) but can't find a thing: Is it possible to test > for the existence of a filehandle? > > I've got a small script that <optionally> opens a filehandle. If that > filehandle exists, I'd like to print to it. Otherwise, don't. e.g., > > use Getopts::Std; > getopts("n"); > open(OPT_LOG,">/tmp/foo.txt") if ($opt_n); > while (<>) { > print OPT_LOG $_ if OPT_LOG; > } > close(OPT_LOG) if OPT_LOG; > > -- > Eric P. > Los Gatos, CA > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -------------------------------------------------------------------------- ------ > This email may contain confidential and privileged > material for the sole use of the intended recipient. > If you are not the intended recipient, please contact > the sender and delete all copies. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]