I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-05-12 16:06:47-07 by pauleym
Using Getopt::Declare
Hi, I have been trying to use Getopt::Declare but without success. Listed below is a small program that attempts to use the module. (Note that in the code for each parameter definition one or more tab characters separate it and the description; all other whitespace in the specification are spaces.) After that are the error messages I get when I try to run my program. (Note that if I use test.pl -v I don't get the message "In verbose mode.") I've read through the Getopt::Delcare documentation many times and it seems that the format of my specification is correct so I don't understand why it is not working. Any help or suggestions would be greatly appreciated. Mark
################################################################################################### +# #! /usr/bin/perl -w use strict; # Prevent unsafe constructs use Getopt::Declare; # Processes command-line parameters (for usage # search http://www.cpan.org for Getopt::Declare) use Bio::Seq; # Use BioPerl packages use Bio::SeqIO; # The parameter definition consists of a leading flag or parameter variable, # followed by any number of parameter variables or punctuators, optionally # separated by spaces. The parameter definition is terminated by the first # tab that is encountered after the start of the parameter definition. At least # one trailing tab must be present. $specification = q( -i <FILE> Input filename --input <FILE> [ditto] (long form) -o <FILE> Output filename --output <FILE> [ditto] (long form) -c Process chaperonin proteins only --chap [ditto] (long form) -n Process non-chaperonin proteins only --nonchap [ditto] (long form) -a Process all proteins --all [ditto] (long form) [mutex: -c --chap -n --nonchap -a -all] # Specifies mutually exclusive options -v Verbose mode (echos output to screen) --verbose [ditto] (long form) [nocase] # Everything is case insensitive -- End of arguments { finish } ); my $args = Getopt::Declare->new($specification); # Determine verbosity my $verbose = 0; # Verbose flag (assumed false) if (($args->{'v'}) or ($args->{'--verbose'})) { $verbose = 1; print "In verbose mode." } my $inFile = ""; # Input filename my $outFile = ""; # Output filename # Get input filename (either from command-line or via user prompt) if ($args->{'-i'}) { $inFile = $args->{'-i'}{'<FILE>'}; } elsif ($args->{'--input'}) { $inFile = $args->{'--input'}{'<FILE>'}; } else { print "Input filename for reading: "; $inFile = <STDIN>; chomp $inFile; } # Get output filename (either from command or via user prompt) if ($args->{'-o'}) { $inFile = $args->{'-o'}{'<FILE>'}; } elsif ($args->{'--output'}) { $inFile = $args->{'--output'}{'<FILE>'}; } else { print "Output filename for writing: "; $outFile = <STDIN>; chomp $outFile; } # Open input file (a FASTA file) my $seqio_obj = Bio::SeqIO->new(-file => $inFile, -format => "fasta" ); # Open output file (simple flatfile) unless (open(OUTPUT, ">$outFile")) { die "Cannot open $outFile for writing. Stopped."; } # Exit the program gracefully exit(0); ###################################################################################################
mpauley@mpauley-desktop:~/projects/yellowstone/chaperones$ ./test.pl --verbose -i microbes_20090422 +.fna -o testout.tab Name "main::OUTPUT" used only once: possible typo at ./test.pl line 90. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 544. Use of uninitialized value in hash element at /usr/local/share/perl/5.8.8/Getopt/Declare.pm line 86 +. Use of uninitialized value in hash element at /usr/local/share/perl/5.8.8/Getopt/Declare.pm line 86 +. Use of uninitialized value in hash element at /usr/local/share/perl/5.8.8/Getopt/Declare.pm line 86 +. Use of uninitialized value in hash element at /usr/local/share/perl/5.8.8/Getopt/Declare.pm line 87 +. Use of uninitialized value in hash element at /usr/local/share/perl/5.8.8/Getopt/Declare.pm line 87 +. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 539. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 539. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 539. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 539. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Getopt/Dec +lare.pm line 539. Can't use string ("microbes_20090422.fna") as a HASH ref while "strict refs" in use at ./test.pl li +ne 65. In verbose mode.
Direct Responses: Write a response