develooper Front page | perl.beginners | Postings from March 2002

creating custom switches in my program?

Thread Previous | Thread Next
From:
M z
Date:
March 7, 2002 08:53
Subject:
creating custom switches in my program?
Message ID:
20020307165231.41953.qmail@web20902.mail.yahoo.com
Mr. Gibbs

thank you for your help

but when I just implemented the use directives and
getopts subroutine call

use strict;
use Getopt::Std;
use vars qw(opt_d);

getopts("d:");

the compiler is complaining, namely

'opt_d' is not a valid variable name at my script ...
BEGIN failed--compilation aborted

I ran this under perl 5.6 on windows 98 for testing
purposes, if you could shed some more light on me that
would be great!




--- Tanton Gibbs <thgibbs@deltafarms.com> wrote:
> use strict;
> use Getopt::Std;
> use vars qw( opt_d );
> 
> getopts( "d" );
> 
> #getopts will set $opt_X where X is the letter of
> the option, so in this
> case it will set $opt_d.  The use vars
> #statement told perl that $opt_d was a global
> variable (much the same as our
> $opt_d, but works on older perls)
> #If opt_d is defined, then the option was specified
> on the command line,
> otherwise it was not given.  If you wanted
> #to take an argument such as myprog -d filename,
> then you would say:
> #getopts("d:")
> #which makes -d take an argument.  Then, the
> argument name would be in
> $opt_d if -d was present.
> 
> if( defined( $opt_d ) ) {
>   print "Option d was given!";
> }
> else {
>   print "Option d was not given!";
> }
> 
> Good luck!
> Tanton
> ----- Original Message -----
> From: "M z" <kpslater777@yahoo.com>
> To: <beginners@perl.org>
> Sent: Tuesday, March 05, 2002 10:26 AM
> Subject: creating custom switches in my program?
> 
> 
> > Hello
> >
> > I was looking into documentation on the getopts
> > module, but was having some difficulty
> understanding
> > how to implement it.
> >
> > The scope of my problem is quite simple, actually.
> > can someone help me create a snippet where if no
> > argument is specified at the command line, than
> the
> > output is written out to the input file, and if an
> > option is given (say -d) at the comment line, the
> > program subsequently prompts the user for the
> > destination to write to?
> >
> > thanks, I think this is easier than I'm making it
> out
> > to be, but I have no experience implementing the
> > getopts module.
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Try FREE Yahoo! Mail - the world's greatest free
> email!
> > http://mail.yahoo.com/
> >
> > --
> > To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> > For additional commands, e-mail:
> beginners-help@perl.org
> >
> 


__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About