Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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
Pattern match and splitting of that
4 direct replies — Read more / Contribute
by Nansh
on Jun 22, 2017 at 09:29
    Hi My string looks like below

    RABBIT 45 -126.06686

    my output should be like 1)RABBIT 2)45 3)-126.06686

    #!usr/bin/perl use strict; use warnings; my $string="RABBIT 45 -126.06686"; (my $temp1)=$string=~ /^(\w+)\s+/; (my $temp2)=$string=~ /^\s+/(\d+)/; (my $temp3)=$string=~ /^(.*)\s+(\d+)\s+$/;
    I am not able to get -126.06686. Thank you.
Pulling from a list and inserting into XML documents
1 direct reply — Read more / Contribute
by gng4life
on Jun 22, 2017 at 09:25
    Hello All, First post so go easy on me. I'm getting back into Perl after not touching it for years so I am like a noob. This is what I need to do. I have text file A that three fields, for example IP address, MAC, hostname, and there about 200 of them, comma separated (I can change this to a csv or whatever if easier). I have about 200 XML documents that I need to search for tags and enter those three fields above into that section, save it, open the next document and enter the same three fields, save, repeat for all docs. Here is an example:
    File A hosta,1.1.1.1,00000C123456, hostb,2.2.2.2,00000C123457, hostc,3.3.3.3,00000C123458, hostd,4.4.4.4,00000C123459, etc...(about 200 items, will have more later) File 1 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 2 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 3 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . After all the docs are done, they will look like this... File 1 . <HOST_NAME>hosta</HOST_NAME> <HOST_IP>,1.1.1.1</HOST_IP> <HOST_MAC>00000C123456</HOST_MAC> . . File 2 . <HOST_NAME>hostb</HOST_NAME> <HOST_IP>,2.2.2.2</HOST_IP> <HOST_MAC>00000C123457</HOST_MAC> . . etc.
    I have portable strawberry Perl right now on my work computer. If it would be easier to do it in ActivePerl or in Strawberry Perl installed version, let me know and I can spin it up on another workstation. So what is the best way to do this? Thanks for any help!
CPAN Installation of Perl Packages Fails
1 direct reply — Read more / Contribute
by m_jaser
on Jun 22, 2017 at 00:39

    Hello Perl Monks

    I've been trying to install some perl packages via CPAN but its failing, see the examples below for your reference. Can you please advise how can I successfully install these packages?

    [~]$ cpan -f -i Device::SerialPort Going to read '/home/emarwja/.cpan/Metadata' Database was generated on Thu, 22 Jun 2017 02:17:02 GMT Running install for module 'Device::SerialPort' Running make for C/CO/COOK/Device-SerialPort-1.04.tar.gz Checksum for /home/emarwja/.cpan/sources/authors/id/C/CO/COOK/Device-S +erialPort-1.04.tar.gz ok CPAN.pm: Going to build C/CO/COOK/Device-SerialPort-1.04.tar.gz To enable serial port tests, use: perl Makefile.PL TESTPORT=<DEVICE> where <DEVICE> is a specific port or 'auto' to autodetect. Running ./configure ... checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: no acceptable C compiler found in $PATH See `config.log' for more details. The 'configure' script didn't like something. It should have told you what went wrong, but you can check 'config.log' for more details. Warning: No success on command[/usr/bin/perl Makefile.PL] COOK/Device-SerialPort-1.04.tar.gz /usr/bin/perl Makefile.PL -- NOT OK Running make test Make had some problems, won't test Running make install Make had some problems, won't install Could not read metadata file. Falling back to other methods to determi +ne prerequisites [~]$

    [~]$ cpan -f -i NET:TELNET Going to read '/home/emarwja/.cpan/Metadata' Database was generated on Thu, 22 Jun 2017 02:17:02 GMT Warning: Cannot install NET:TELNET, don't know what it is. Try the command i /NET:TELNET/ to find objects with matching identifiers. [~]$ [~]$ cpan -f -i NET:SSH Going to read '/home/emarwja/.cpan/Metadata' Database was generated on Thu, 22 Jun 2017 02:17:02 GMT Warning: Cannot install NET:SSH, don't know what it is. Try the command i /NET:SSH/ to find objects with matching identifiers. [~]$
An overlapping regex capture
2 direct replies — Read more / Contribute
by Peter Keystrokes
on Jun 21, 2017 at 15:18

    Hi there,

    I have a script which extracts sequences from a file containing thousands of fasta sequences and creates separate files for each of them.

    Here is my script:

    #!/usr/bin/perl use strict; use warnings; my %id2seq = (); my $id = ''; open File,"human_hg19_circRNAs_putative_spliced_sequence.fa",or die $! +; while(<File>){ chomp; if($_ =~ /^>(.+)/){ $id = $1; }else{ $id2seq{$id} .= $_; } } foreach $id (keys %id2seq){ if (-f $id){ print $id." Already exists, about to override it","\n" } open my $out_fh, '>>', "$id.fa" or die $!; print $out_fh (">".$id."\n",$id2seq{$id}, "\n"); close $out_fh; } close File;

    Now, the human_hg19_circRNAs_putative_spliced_sequence.fa file which I am working on contains sequences as such:

    >hsa_circ_0000001|chr1:1080738-1080845-|None|None

    ATGGGGTTGGGTCAGCCGTGCGGTCAGGTCAGGTCGGCCATGAGGTCAGGTGGGGTCGGCCATGAAGGTGGTGGGGGTCATGAGGTCACAAGGGGGTCGGCCATGTG

    My script captures each sequence header as the key of a hash and captures the sequence itself as the hash. But the problem is that I want to name the files with only a part of the $id and not the whole of it i.e. hsa_circ_0000001.

    Is there a simple way to do this? Or do I have to create a new hash to extract filenames?

    Pete.

from txt file to array
6 direct replies — Read more / Contribute
by WisDomSeeKer34
on Jun 21, 2017 at 15:01

    I have raw data like this:

    Washington
    New York
    Louisiana
    Georgia
    Texas
    Iowa
    etc.

    and I want to turn it into an array:
    qw (Washington, New York ....);

    I can do it manually but it is a fuzz to do it every time.
    Is it perhaps possible with while (< DATA >)? How to input raw data into a perl script?

using a 'here' doc to build a web page
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 21, 2017 at 11:23
    I am constructing a web page by first defining variables which are extrapolated in the 'HERE' document. I am creating a HTML file by printing the 'HERE' document. It seems to be working OK. Is this a valid approach?
Win32::GUI - error adding a bitmap in button
3 direct replies — Read more / Contribute
by levW
on Jun 21, 2017 at 10:55

    Win32::GUI - error adding a bitmap in button:

    my @bitmap; my $path1 = "reload-page.jpg"; my $icoImage = new Win32::GUI::Bitmap($path1) || warn "bitmap:$!\n"; push(@bitmap, $icoImage); $buttons->{$counters1} = $main->AddButton(-name =>"ReloadUsers", -text + => "ReloadUsers",-font => $font13,-pos => [ 600, 101 ], -onClick => sub {&ReloadUsers});

    Getting an error: bitmap:Bad file descriptor....

    Will appreciate any help

Padre Installation Error (Major)
4 direct replies — Read more / Contribute
by WizardOfPerl
on Jun 21, 2017 at 07:34
    I've recently moved onto a Windows 10 PC and have just installed DWIM Perl on it.
    It installed correctly, but whenever I run Padre (the IDE) from the start menu it returns the following error

    Major Startup Error: 'syntax error at (eval 1907) line 23, next token +??? (Might be a runaway multi-line PP string starting on line 13) Unmatched right curly bracket (eval 1907) line 26, at end of line syntax error at (eval 1907) line 67, near";}" syntax error at (eval 1907) line 78, near";}" syntax error at (eval 1907) line 84, near";}" syntax error at (eval 1907) line 92, near";}" syntax error at (eval 1907) line 98, near";}" syntax error at (eval 1907) line 110, near";}" syntax error at (eval 1907) line 116, near";}" syntax error at (eval 1907) line 137, near";}" (eval 1907) has too many errors. BEGIN failed -- compilation aborted at C:/Dwimperl/perl/site/lib/Padre +/DB.pm line 36. Compilation failed in require at C:/Dwimperl/perl/site/lib/Padre.pm li +ne 33 BEGIN failed -- compilation aborted at C:/Dwimperl/perl/site/lib/Padre +.pm line 33. Compilation failed in require '
Replace and substitur in same file
3 direct replies — Read more / Contribute
by Nansh
on Jun 20, 2017 at 22:20
    Hi, I have file like this

    Eg: I have a Red car

    I love Red car

    <p But I have a lot of affection with car

    #!usr/bin/perl open(DAT,"something/something/something"); while(<DAT>) { $_=~ s/(.*)/Red car/g; print DAT $_; }
    I want to Substitute whole file with Red car Thank you
Capturing and then opening multiple files
4 direct replies — Read more / Contribute
by Peter Keystrokes
on Jun 20, 2017 at 16:06
    Hi there, If I have a folder that contains the following files:

    hsa_circ_0000007.fa.txt_palindromes.csv

    hsa_circ_0000008.fa.txt_palindromes.csv

    hsa_circ_0000009.fa.txt_palindromes.csv

    hsa_circ_0000010.fa.txt_palindromes.csv

    And i then use:

    my @pal_files = glob("*palindromes.csv");

    Am I just feeding the plain names into an array or am I capturing the entire file into the array?

    My hunch is that I'm just capturing the name of the file.

    How then do I capture all the files with the extension of my choice so that I can then open those files to extract data?

    Pete.

Add your question
Title:
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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (8)
    As of 2017-06-22 14:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How many monitors do you use while coding?















      Results (522 votes). Check out past polls.