Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Seekers of Perl Wisdom

( #479=superdoc: print w/replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
finding sequence
3 direct replies — Read more / Contribute
by yueli711
on Jun 22, 2018 at 14:05

    Hello, I want to find the sequences in tmp01 which are containing in tmp02, then print all of them out. Tab seperated tmp02 file. Thanks in advance!

    open(IN1,"tmp01") || die "Cannot open this file"; @lines1 = <IN1>; open(IN2,"tmp02") || die "Cannot open this file"; @lines2 = <IN2>; open(OUT,">tmp03") || die "Cannot open this file"; for $item1(@lines1){ chomp $item1; #print OUT $item1,"\t"; @tmp1=split(/\t+/, $item1); for $item2(@lines2){ chomp $item2; @tmp2=split(/\t+/, $item2); if ($tmp1[0] =~m/ *$tmp2[0]*){ print OUT $item1,"\t",$item2; #last; } $i++ } print OUT "\n"; } close(IN1); close(IN2); close(OUT);
Using 'no warnings' to disable own debug warn(ing)s?
1 direct reply — Read more / Contribute
by LanX
on Jun 22, 2018 at 13:13
    According to warnings and perldiag it's possible to disable special warning classes in a lexical scope. (like the uninitialized one in the example)

    Is it also possible to use this mechanism to disable my own debug messages for a scope?

    (I'm aware about the possibility to manipulate $SIG{"__WARN__"} handler, but trying not to reinvent the wheel².)

    use strict; use warnings; my $x; { no warnings; # no warnings 'uninitialized'; print "$x"; warn "inside"; } print "$x"; warn "outside";
    inside at d:/Users/lanx/pm/ line 9. Use of uninitialized value $x in string at d:/Users/lanx/pm/ + line 11. outside at d:/Users/lanx/pm/ line 12.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    ²) and overusing Pad::Walker

PAR::Packer Fail install Perlbrew
No replies — Read more | Post response
by Anonymous Monk
on Jun 22, 2018 at 12:24

    I am on macOS (HighSierra) using Perlbrew. I have problems to install PAR::Packer, as it fails with this error:

    --> Working on PAR::Packer Fetching +tar.gz ... OK ==> Found dependencies: DynaLoader skipping N/NW/NWCLARK/perl-5.8.6.tar.gz ! Installing the dependencies failed: Module 'DynaLoader' is not insta +lled ! Bailing out the installation for PAR-Packer-1.045.

    I have on the same machine several Perl installation. Never had a problem to install this module. However, I noticed that if I use

    perlbrew available

    I get a rather short list of cperl. This was not the case until a couple of months ago, where I got a list of perl. I have PAR::Packer installed with perl-5.24.4, however on both cperl-5.27.2 and cperl-5.26.2 it fails with me message above. Any idea?

not well-formed (invalid token) while using SOAP Lite Module
No replies — Read more | Post response
by Perl_Jay
on Jun 22, 2018 at 11:11
pp filter regex
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jun 22, 2018 at 08:22

    What is wrong in this command for pp and the filter option on Windows?

    pp -u -g -o MyExe -F Bleach='^(GUI_|AA_|myMainScript)'

    the regex should pass to the bleach routines all modules starting with GUI_, AA_. etc.

Any downsides to this slurp idiom?
8 direct replies — Read more / Contribute
by haukex
on Jun 22, 2018 at 07:33

    I sometimes use (and suggest) this to slurp a file in a single line:

    my $data = do { open my $fh, '<', $file or die $!; local $/; <$fh> };

    The lexical filehandle should be automatically closed at the end of the block. Can anyone think of any downsides to the above? Like perhaps some subtle scoping issue, or it's bad style to rely on the implicit close, etc. ... or am I just being paranoid?

    Update: Typo fix, $/ not $\, thanks Corion!

Perl script that will read two pdb files with different line numbers and will replace the chain letter from the first to the second file
3 direct replies — Read more / Contribute
by Nastazia
on Jun 22, 2018 at 05:57

    Hello everyone, I am trying to write a script in perl which will do the following

    it will read a pdb file that contains only Ca atoms as the following

    1 2 3 4 5 6 ATOM 1 CA PRO A 889 84.370 72.820 26.830 1.00 0.00 + ATOM 2 CA THR A 890 87.370 73.900 28.080 1.00 0.00 + ATOM 3 CA VAL A 891 90.920 72.490 27.750 1.00 0.00 + ATOM 4 CA PHE A 892 93.640 74.890 28.970 1.00 0.00 + ATOM 5 CA HIS B 893 97.060 74.200 27.360 1.00 0.00 + ATOM 6 CA LYS B 894 99.880 73.920 29.990 1.00 0.00

    it will read a second pdb that contains every atom

    1 2 3 4 5 6 ATOM 1 N PRO A 889 16.220 12.185 1.804 1.00 71.54 + N ATOM 2 CA PRO A 889 16.101 12.990 3.034 1.00 70.89 + C ATOM 3 C PRO A 889 15.432 14.346 2.803 1.00 72.31 + C ATOM 4 O PRO A 889 14.743 14.852 3.703 1.00 72.20 + O ATOM 5 CB PRO A 889 17.553 13.151 3.502 1.00 72.96 + C ATOM 6 CG PRO A 889 18.315 12.067 2.782 1.00 78.00 + C ATOM 7 CD PRO A 889 17.626 11.907 1.465 1.00 73.35 + C

    (The files refer to the same molecule but have different number of lines)

    So if the residue number (column num 5) is the same it will take the chain letter (column num 4) from the first file and replace all the chain letters that have the same residue number in the second file. So far i've got this disaster :/

    print "\nEnter the network pdb file file: "; $inputFile = <STDIN>; chomp $inputFile; unless (open(INPUTFILE, $inputFile)) { print "Cannot read from '$inputFile'"; <STDIN>; exit; } # load the file into an array chomp(@networkpdb = <INPUTFILE>); # close the file close(INPUTFILE); print "\nEnter the pdb output file: "; $inputFile2 = <STDIN>; chomp $inputFile2; unless (open(INPUTFILE, $inputFile2)) { print "Cannot read from '$inputFile2'"; <STDIN>; exit; } chomp(@pdb = <INPUTFILE>); close(INPUTFILE); for ($line1 = 0; $line1 < scalar @networkpdb; $line1++) { if ($networkpdb[$line1] =~ m/ATOM\s+\d+\s+\w+\s+\w{3}\s*(\w+)\s*(\ +d*)\s+\S+\.\S+\s+\S+\.\S+\s+\S+\.\S+\s+.+\..+\..*/ig) { my $resnum=$2; my $chain=$1; for ($line = 0; $line < scalar @pdb; $line++) { if ($pdb[$line]=~ m/(ATOM\s+\d+\s+\w+\s+\w{3}\s*)(\w+)\s*(\d*)(\s ++\S+\.\S+\s+\S+\.\S+\s+\S+\.\S+\s+.+\..+\..*)/ig) { my $begining=$1; my $resnum1=$3; my $chain1=$2; my $end=$4; if ($resnum1=$resnum) {$chain1=$chain; $parsedData{$line} = $begining.$chain1."\s".$resnum1.$end; }}}}} # create the output file name $outputFile = "WithNetwork_".$inputFile; # open the output file open (OUTFILE, ">$outputFile"); # print the data lines foreach $line (sort {$a <=> $b} keys %parsedData) { print OUTFILE $parsedData{$line}."\n"; } # close the output file close (OUTFILE);

    thank you very much in advance

Will 'when()' be removed or deprecated in upcoming version of Perl?
3 direct replies — Read more / Contribute
by Darkwing
on Jun 22, 2018 at 02:57
    Every now and then i use something this in my code:
    for ($foo) { when (/blah/) {...} when (/xyz/) {...} ... }
    Now this page Beware of the removal of when in Perl v5.28 tells that when() will be removed in perl 5.28, meaning that i would need to change such code. But on this page perldeprecation there is nothing written about removing when() or marking it deprecated. Now, what is correct about the when()?
How to convert the NCBI Gene ID to GenBank ID?
2 direct replies — Read more / Contribute
by supriyoch_2008
on Jun 22, 2018 at 02:50

    Hi Perl Monks,

    I am interested in converting the Gene ID of NCBI to GenBank ID. In NCBI Gene database, when I write 7157 as Gene ID in search box, the page opens with the heading "TP53 tumor protein p53 Homo sapiens (human)". Almost at the bottom of that page the sub-heading appears as "mRNA and Protein(s)" which shows the GenBank ID as "NM_000546.5" (first entry) with a hyperlink. When clicked, the GenBank page opens up and shows the details. This is a cumbersome process when one has to get the GenBank ID of many genes. I searched in the web for a perl script which can convert Gene ID to GenBank ID using internet directly. But I did not get such a script. However, the link can perform this task of conversion in a very lengthy procedure. Then, I tried to get the sequence of Gene ID 7157 using a script:

    Here goes the script for sequence:

    #!/usr/bin/perl use warnings; use strict; use Bio::DB::GenBank; use Bio::SeqIO; use Text::Wrap; my $gb= new Bio::DB::GenBank; my $id='7157'; my $seq = $gb->get_Seq_by_gi($id); print "\n seq: $seq\n"; exit;

    But I got the wrong result and not the sequence in cmd as follows: Here goes the result in cmd:

    C:\Users\x>cd d* C:\Users\x\Desktop> seq: Bio::Seq::RichSeq=HASH(0x780b234) C:\Users\x\Desktop>

    I need suggestions from PerlMonks to solve this problem of ID conversion so that I can get the results of Gene IDs: 7157, 7422 as follows in cmd:

    I expect results in the following format:

    GenBank ID NM_000546.5 NM_001025366.2
PERL-CGI on shared unix server
4 direct replies — Read more / Contribute
by rahu_6697
on Jun 22, 2018 at 01:43

    Hello to all! I am new to perl-cgi, just trying to execute my first program and stored it as in my home directory. I am working on a shared unix based server so I don't have access to var/www/cgi-bin folder of my directory and there is not any webserver package installed. So how should i run this type of files. Please provide step by step procedure for running this file such that on browser Hello World! should display.

    #!/usr/local/bin/perl print "Content-Type: text/html\n\n"; print "<html> <head>\n"; print "<title>Hello, world!</title>"; print "</head>\n"; print "<body>\n"; print "<h1>Hello, world!</h1>\n"; print "</body> </html>\n";

Add your question
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2018-06-23 01:50 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.