Proper argument processing 
Author Message
 Proper argument processing

I have a few questions about the proper way to get command line
arguments using Getopt::Std while using strict and diagnostics.

For example:
------------------
#!/usr/local/bin/perl -w

use strict;
use diagnostics;

use Getopt::Std;
getopts('f:');

my $InFile = $opt_f if (defined $opt_f);

print "$Infile\n";
-------------------
Gives me a "requires explicit package name at line 9" message. I have
tried defining the options but haven't found a way to get rid of these
messages other than commenting out use strict and use diagnostic.

Another problem I have is if I do something like:

  my $InFile = $opt_f;

then I am only using $opt_f once, so I get the you might have had a Typo
messages.
How do people handle this situation?



Sun, 27 Feb 2000 03:00:00 GMT  
 Proper argument processing

Quote:

> I have a few questions about the proper way to get command line
> arguments using Getopt::Std while using strict and diagnostics.

> For example:
> ------------------
> #!/usr/local/bin/perl -w

> use strict;
> use diagnostics;

> use Getopt::Std;
> getopts('f:');

> my $InFile = $opt_f if (defined $opt_f);

> print "$Infile\n";
> -------------------
> Gives me a "requires explicit package name at line 9" message. I have
> tried defining the options but haven't found a way to get rid of these
> messages other than commenting out use strict and use diagnostic.

> Another problem I have is if I do something like:

>   my $InFile = $opt_f;

> then I am only using $opt_f once, so I get the you might have had a Typo
> messages.
> How do people handle this situation?

The
use strict;
is causing the "problem"

You need to add a

use vars qw($opt_f);

use vars lets you predeclare global variable names in a script.

This will get rid of the use strict errors and the typo warnings
as well, if I remember properly.

Hope this helps,
  Ty

+---+

Systems Engineer                                                 InfiNet
Homepage: http://tazer.engrs.infi.net/~tycage
PGP Public Key: http://tazer.engrs.infi.net/~tycage/pgpkey.html
PGP Fingerprint: FF C1 28 CA 80 B5 31 78  B1 24 2E 8C AB DA FB D2
------------->Never invoke anything bigger than your head.<-------------



Mon, 28 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Multithreaded servers and communicating object processes (proper)

2. patch1 for wafeperl 0.2 to allow xt command line argument processing

3. Passing arguments to a server process

4. Associative arguments as arguments in Perl 5.002

5. Proper way to break module backwards-compatibility?

6. Proper Perl System Calls from cgi-bin

7. proper way to use new version of a module

8. Proper Capitalization of Names

9. Proper way to update libnet wrt Netconfig.pm

10. Advice on proper command to use

11. Proper pipe handling

12. Proper way to use gethostbyaddr?

 

 
Powered by phpBB® Forum Software