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 5 years ago.
Improve this question
The following perl script takes an argument from the command line and use that as the output file name.
my $str = $ARGV[0];
my $out_handler= Bio::SeqIO->new(
-file => $str,
-format => 'Fasta'
);
It is similar to this example. while I run perl test.pl polg, I get this error
------------- EXCEPTION -------------
MSG: Could not read file 'polg': No such file or directory
STACK Bio::Root::IO::_initialize_io /opt/perl/lib/site_perl/5.14.2/Bio/Root/IO.pm:268
STACK Bio::SeqIO::_initialize /opt/perl/lib/site_perl/5.14.2/Bio/SeqIO.pm:513
STACK Bio::SeqIO::fasta::_initialize /opt/perl/lib/site_perl/5.14.2/Bio/SeqIO/fasta.pm:87
STACK Bio::SeqIO::new /opt/perl/lib/site_perl/5.14.2/Bio/SeqIO.pm:389
STACK Bio::SeqIO::new /opt/perl/lib/site_perl/5.14.2/Bio/SeqIO.pm:435
STACK toplevel test.pl:16
-------------------------------------
How can I fix that?
Your program is trying to read from that file and failing because it doesn't exist
Your example code on github has this
-file => '>chrom20.fasta'
so I suggest you should try
-file => ">$str"
or you can run your program as
perl test.pl >polg
Also, I'm sure you can think of a better name than $str for a scalar variable containing an output file name. $str is only fractionally better than $var
Related
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 5 years ago.
Improve this question
Here by i tried to swap the variables using perl.
#!/usr/local/bin/perl
use strict;
use warnings;
my $v1=23;
my $v2=43;
$v1,$v2)=($v2,$v1)
print $v1,$v2;
Error:
syntax error at exchange.pl line 7, near ")
print"
Execution of exchange.pl aborted due to compilation errors.
Excepted output:
43,23
You forgot open parens and semicolon:
($v1,$v2)=($v2,$v1);
print $v1,$v2;
Expected output should be 4323 (4 chars and no comma), not 43,23.
To print 43,23:
print "$v1,$v2";
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 7 years ago.
Improve this question
&verify_se_linecount ( \#rows );
### Drop the modified file
open ( OUT, "> $RESOLVED_DIR\\$filenameonly" );
# Loop through each row in the EDI file
foreach my $row ( #rows ) {
print OUT $row . "$ROW_DELIM"; # Line 164
}
close OUT;
I have a Perl script (the code above is part of it) that works perfectly on a test server but shows a compilation error on a production server. The error is
Global symbol `$ROW_DELIM` requires explicit package name at <script_name> line 164
The variable is declared with our $ROW_DELIM in a package which is imported in this script. It does not show any error for other objects used from that package.
Without being able to see how you export/import the function - it'll be one of these things:
You've declared it with my in your package.
You aren't exporting it like you think
You aren't importing it like you think.
Try $OtherPackageName::ROW_DELIM and see if that works.
It isn't enough to declare the variable in a module that your main code uses: you have to export it from that module to make it visible elsewhere
If you need any further help then you must show the contents of the module, together with the statement that imports it into the main code
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.