in reply to array empty when calling script with getopt::long
In addition to what has been said, you could make the array variable "aminos" global, so that it can be accessed by all. But it's better to make a variable available close to where it's are needed.
Your values to your scalar variables maybe gotten from the CLI and checked if initialized.
Modifying your post a bit like this works, but you might still have to work on it or incorporate it with your code.
You might have to check the usage of Getopt::Long again.use warnings; use strict; use Getopt::Long qw(:config gnu_getopt); help() if $ARGV[0] !~ /^--/; my @aminos = qw (A R N D C Q E G H I L K M F P S T W Y V B Z X); GetOptions( 'substr1=s' => \my $substr1, 'substr2=s' => \my $substr2, 'sub' => \&a, 'help|?' => \&help, ); sub a { if ( "$substr1$substr2" =~ /[^@aminos]/ ) { print "hello\n"; } print "@aminos\n"; } sub help { print "Usage: script --substr1 value --substr2 value --sub" +; exit }
Note, I didn't check for the initialization of substr1 and 2
|
|---|