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";
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
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
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
#!/usr/bin/perl
$rank=1;
$name="Saumik";
$tot_money=55555555.55;
$my_oct=0167;
$my_hex=0xabe;
print "Name: $name\n";
print "Rank $rank\n";
print "Total Prize Money: $tot_money\n";
print "My Octal Number: $my_oct\n";
print "My Hexadecimal Number: $my_hex\n":
syntax error at salar.pl line 14, near ""My Hexadecimal Number: $my_hex\n":" Execution of salar.pl aborted due to compilation errors. Press any key to continue
print "My Hexadecimal Number: $my_hex\n":
---^
Syntax error - it should be a semicolon.
Also: Turn on use strict; and use warnings; You can also format your code on Stack Overflow by selecting it and pressing ctrl + k (whilst in edit mode). However if you are getting an error - it's useful to include that in your post.
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 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 8 years ago.
Improve this question
I have a code like:
my ($line_1, $line2);
variables $line_1 and $line_2 are getting values from other function, that may be a defined or undefined value.
Now I am getting an error like " Use of uninitialized value" evenafter i have initialised like
$line_1 = " " if(!$line_1);
PLease help me in this
To check for the definedness (whether it is undef or not) of a variable, use the defined operator.
If you still get the warning, perl is right and your code is wrong. No magic here.
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.