Front page | perl.beginners |
Postings from March 2002
Re: Testing for filehandles
Thread Previous
|
Thread Next
From:
Agustin Rivera
Date:
March 27, 2002 14:48
Subject:
Re: Testing for filehandles
Message ID:
009801c1d5e1$471fd170$9865fea9@agustinr
Ok, I've tried it both ways and it returns 1 (true) as the value. What am I
doing wrong?
#!/usr/bin/perl
use strict;
use Getopt::Std;
my %opt;
getopts('h', \%opt);
print "$opt{h}\n";
Agustin Rivera
Webmaster, Pollstar.com
http://www.pollstar.com
----- Original Message -----
From: "Chas Owens" <cowens@intercall.com>
To: "Agustin Rivera" <lists@eleqtriq.ws>
Cc: "Beginners Perl Mailing List" <beginners@perl.org>
Sent: Wednesday, March 27, 2002 1:51 PM
Subject: Re: Testing for filehandles
> Getopt::Std creates the $opt_n variables. To use it with use strict; in
> place you must use the use vars ($opt_n); pragma as well. or just use
> the getopts('n', \%opts); call. Then you can say $opts{n}.
>
> On Wed, 2002-03-27 at 16:46, Agustin Rivera wrote:
> > 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" <tjohnson@sandisk.com>
> > To: <eric-perl@pretorious.net>; "Beginners Perl Mailing List"
> > <beginners@perl.org>
> > 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: eric-perl@pretorious.net [mailto:eric-perl@pretorious.net]
> > > 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: beginners-unsubscribe@perl.org
> > > For additional commands, e-mail: beginners-help@perl.org
> > >
> > >
> >
> --------------------------------------------------------------------------
> > ------
> > > 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: beginners-unsubscribe@perl.org
> > > For additional commands, e-mail: beginners-help@perl.org
> >
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > For additional commands, e-mail: beginners-help@perl.org
> >
> >
> --
> Today is Sweetmorn the 13rd day of Discord in the YOLD 3168
> Grudnuk demand sustenance!
>
> Missile Address: 33:48:3.521N 84:23:34.786W
Thread Previous
|
Thread Next