Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I used $var=$ARGV[0] in some Perl code on a Solaris x64 machine and it is receiving the argument correctly.
But the same piece of code is not working in Solaris SPARC.
Any clue?
Also $_[0] is working in Solaris SPARC, but then it is not working in Solaris x64.
Is there any other way?
Try this program:
use strict;
use warnings;
print join ": ", #ARGV . "\n";
Run it with a bunch of command line arguments, and tell me what you're getting as an output. It should look something like this:
$ myprog.pl one two three four five
one: two: three: four: five
Next, try the same thing with this program:
use strict;
use warnings;
print join ": ", #ARGV . "\n";
my $value = $ARGV[0];
print qq(My value = "$value"\n);
Now, edit your question to show us the output you're getting. This way, we'll know what you mean. Also, give us at least a code snippet of what is not working, what you expect, and what you're getting.
Writing a quick etest program is always a good way to track down an issue, and can give you something to post on Stackoverflow if you're still stuck.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I read try to read perl code of annovar and there is a line like this:
push #{$genedb{$chr, $nextbin}}, [$name, $dbstrand, $txstart, $txend, $cdsstart, $cdsend, [#exonstart], [#exonend], $name2];
Can someone explain what does it mean?
which values put which array or hash ?
Just run this program and Data::Dumper will show the results
#! /usr/bin/env perl
use warnings;
use strict;
use utf8;
use feature qw<say>;
use Data::Dumper;
my %genedb;
my $chr = 'G';
my $nextbin = 4143;
push #{$genedb{$chr, $nextbin}}, [1..10];
print Dumper(\%genedb);
exit(0);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm running a perl script with a lot of input options, one of them being:
'errorcode=s{1,}' => \#ecodes,
I have a die at the end of the GetOptions if anything entered doesn't match the input. However if I input '--ecode 500' the program runs.
Why isn't the script dying? If I try something else like '--testing 123' it does die.
I'm guessing you have a option with a required argument such as
"foo=s" => \$foo,
and that you did something like
program --foo --ecode 500
which puts --ecode in $foo and 500 in #ARGV.
$ perl -MGetopt::Long -e'
use feature qw( say );
GetOptions("foo=s" => \$foo)
or die "usage\n";
say "ok <$foo> <#ARGV>";
' -- \
--ecode 500
Unknown option: ecode
usage
$ perl -MGetopt::Long -e'
use feature qw( say );
GetOptions("foo=s" => \$foo)
or die "usage\n";
say "ok <$foo> <#ARGV>";
' -- \
--foo --ecode 500
ok <--ecode> <500>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to do command line argument parsing for a directory path in perl. I want to make this argument as optional.
so when the user gives path, it showed be assigned to a variable $release_model else it will execute other code I have written for finding directory from main directory. I am new to perl but somehow coded following. Can anybody help?
Getopt::Long
my $command_line = $GetOptions(\%Opts, "help|h","email=s#","test","model");
if($command_line==0){
print "$PROGRAM: no arguments are given";
Usage{};
}
else die "No arguments were given"
But it doesn't accept model as optional argument and throws error.
I just started working with perl.
It is quite hard to guess what exactly you are after as the code provided contains lots of errors and other features not described. But to start learning with something simple, here is something that I hope matches your requirements.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $release_model = '/path/to/"main directory"'; # default value
GetOptions( 'model=s' => \$release_model )
or die("Error in command line arguments\n");
print "Release model is: $release_model\n";
If you save this to a file (e.g. my_program.pl) and make it executable then you can see it provides these features:
If you call it without arguments ./my_program.pl, the default value of $release_model will be used.
If you call it with argument model (e.g. ./my_program.pl --model /another/directory), the provided value will be assigned to $release_model.
If you call it with wrong arguments (e.g. ./my_program.pl --mdoel), it prints reasonable error message and exits.
Try it yourself. And go and read some tutorial on Perl if you want to do some serious work.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm a beginner of Perl, using Ubuntu 12.04 as my operating system.
My perl version is v5.14.2.
I wrote a simple program to read user input then print it.
#!/usr/bin/perl
print "please enter your name:";
my $name = ;
print "\n";
print "hello, $name\n";
When I tried to execute this program it turned out to be like this,
syntax error at input.pl line 3, near "=;"
Execution of input.pl aborted due to compilation errors`
But this is a sample code which I copied from a perl textbook, so it shouldn't be any mistake in the code.
that code makes no sense, as the compiler tells you:
my $name = ;
write something like:
my $name = <>;
To be more explicit:
my $name = <STDIN>;
which reads from the standar input, or:
my $name = readline(*STDIN);
If you do my $name = <>;, it will read either from a file specified on the command line or from STDIN if no file is specified
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Why does the following script take so many cycles to complete?
The document it is sifting through is 20590 lines long and each line consists of the following, or a variation thereof;
"10160354001 ALGIERS ALGERIA 36.70 3.60 290"
I am trying to make a database to match the first number to the last 3.
The actual program is however taking several seconds per line.
Script:
#! /usr/bin/perl
$path = shift(#ARGV);
open COORDS, $path or die "Couldn't open file\n";
my %coords = {};
foreach $line (<COORDS>){
$stat = substr $line,0,11;
#coords = grep(($_!=undef),split(/ /,substr $line,42));
$coords[$stat]=#coords;
}
print $coords['10160354001'];
close(COORDS);
$coords['10160354001'] = ... is an assignment to an array element, and a large one at that. This statement will cause Perl to allocate an array with room for at least 10160354002 elements.
You meant to use a hash:
$coords{$stat} = "#coords";
...
print $coords{'10160354001'};
use strict and use warnings would have alerted you to this and other problems with your code.