what does it mean 'push #{bla bla }' in Perl? [closed] - perl

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);

Related

How can I write a Perl function that can generate a random DNA sequence [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I want to write a Perl subroutine using rand() function that generates a random DNA sequence of specified length n. The length n of the sequence is passed as an argument to the subroutine.
I would appreciate if someone could help me out as I am a beginner in perl.
FYI normally you put anything that you have tried so far, Stack Overflow isn't a code writing service.
With that in mind, the best way to do this in my humble opinion is with Perl's rand function:
#!/usr/bin/env perl
use strict; use warnings;
use autodie ':all';
use feature 'say';
my #letters = qw(A C G T);
sub random_DNA {
my $length = shift;
my $seq = '';
foreach my $n (1..$length) {
$seq .= $letters[rand(4)]
}
return $seq
}
foreach my $length (1..9) {
say random_DNA($length)
}
which outputs
con#V:~/Scripts$ perl random_DNA.pl
T
TT
TGG
TGTC
ATGAC
AACGAG
CGGGGTT
CCGTCGTC
TGGCCTCGA
your output will probably not be identical to this, of course, as this is a random function. I prefer not to use modules if I can avoid them, to avoid portability issues, especially with tasks that take a minute to write, like this one.

Perl - Global symbol $DIR requires explicit package name (why can't I print the output?) [closed]

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 6 years ago.
Improve this question
#!/db/pub/infra/CPAN/perl/5.8.8/bin/perl
use lib '/db/pub/eq/arina/global/perl/lib';
use lib '/db/pub/infra/CPAN/perl/5.8.8/lib/site_perl/5.8.8';
use DBI;
use strict;
sub main {
my $dir = "/data/dbxpc2_archive/BookingManager/2017-01-12/data/PC1/millennium.ignore.ftp.noencrypt.DB_USD";
my #files = glob "${DIR}/*.csv";
print #files;
}
main();
You get the error because you are using a variable ($DIR) you never declared. You do have a declared a variable named $dir which appears to be the one you intended to use.
glob "${dir}/*.csv"
glob "$dir/*.csv"
glob $dir."/*.csv"
Your code mishandles paths with spaces, *, ?, etc. Fix the injection bug using
glob "\Q${dir}\E/*.csv"
glob "\Q$dir\E/*.csv"
glob quotemeta($dir)."/*.csv"

Variable scope in perl [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am using CGI in strict mode and a bit confused with variables. I am reading a file that has two lines. Storing both in two variables. But when i try outputing them using html, it says global variable error
This is what I am doing
open TEXT, "filename";
$title = <TEXT>;
$about = <TEXT>;
close TEXT;
but this gives the global variable error. whats the best way to fix this?
You need to declare variable with my to make its scope local. This is the best practice and compulsory when using strict
use strict;
use warnings;
open my $fh, '<', 'filename' or die $!;
my ( $title, $about ) = <$fh>;
close $fh;
Further improvements:
Avoided bareword file handles (e.g. FILE). Instead use local file handles such as my $fh
Used error handling with die when dealing with file processing
Combined assignment of $title and $about as suggested by #Suic
use warnings to display what's going wrong as pointed out by #TLP

$ARGV[0] is not working in Solaris SPARC [closed]

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.

perl programming to make function calls [closed]

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 want to call a function from my program.So can I save the function in another file instead of mixing with the script from where I am calling the function.If so ,with what name should I save the file with function.Please help..
You can write a module. Here is a small module:
File Foo.pm
# declare a namespace
package Foo;
# always use these, they help you find errors
use strict; use warnings;
sub foo {
print "Hello, this is Foo\n";
}
# a true value as last statement.
1;
You place that file into the same directory as your script:
File script.pl:
use strict; use warnings;
# load the module
use Foo;
Foo::foo(); # invoke the function via the fully qualified name
To create nicer modules, you'll probably look into object orientation, or the Exporter module.