Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
Creating a perl delete statement with MongoDB
3 direct replies — Read more / Contribute
by e0s
on Jul 20, 2017 at 08:44

    I am having difficulty creating a perl MongoDB delete statement that will select from EITHER one table or another, depending on the TYPE of input from the user. Let's say the databases are $FRUITS and each fruit is categorized into tables either by their 'fruit_names' or unique 'fruit_ids'

    Let's say the user wants to delete an entry from the fruit_names table, how do I configure my perl code so that it can differentiate between one input versus another?

    I've searched cpan.org and found some MongoDB documentation on delete_one and delete_many but I haven't been able to figure out how I would create a delete_one statement that would pull from either one table or the other, depending on the user's input.

    I am a novice with perl still and I've never used MongoDB before, i've been really stuck on this for a while so any help would be greatly, greatly appreciated.

sysread() is deprecated on :utf8 handles
4 direct replies — Read more / Contribute
by mje
on Jul 20, 2017 at 07:02

    I have just tested some code on Perl 5.24.2 which was running happily on 5.16.0 and got a warning of "sysread() is deprecated on :utf8 handles". Now I'm wondering how to fix it and I'm a little confused by the discussion at RFC remove strange behaviour of sysread()/syswrite() on UTF-8 streams.

    The file handle in question is a unidirectional pipe created before a fork and the parent is writing XML down the pipe (which has :encoding(UTF-8)) layer and the child is using sysread on the read end of the pipe which also has encoding(UTF-8). The child then sends the data down a socket which also has encoding(UTF-8) layer on it.

    I'm slightly confused by the :utf8 and encoding("UTF-8"). I'm doing the latter but the RFC seems to indicate there is a difference between :utf8 and encoding("UTF-8") and that sysread works with :utf8 but not encoding(something else)? So why do I get the deprecated warning?

    Is the solution simply to leave the encoding on the write end of the pipe which uses print to send messages down the pipe, but leave it off the read end of the pipe and decode the read message as UTF8 before sending it down the onwards socket?

    CORRECTION: the connection between the parent and child is a socket although I don't think it makes any difference

    UPDATE1: It appears I can't just use :raw on the socket read end and decode to UTF-8 as I might have read part of a UTF-8 sequence. Still searching for an answer.

    UPDATE2: The code was originally using readline but that was switched to sysread because the code already uses IO::Select and you cannot mix buffered reading with IO::Select

    UPDATE3: This link explains why you cannot use buffered IO and IO::Select https://stackoverflow.com/questions/7349124/is-it-ever-safe-to-combine-select2-and-buffered-io-for-file-handles#7352605

error: Use of uninitialized value in print at enhancement.pl line 31, <$readhandle> line 4.
2 direct replies — Read more / Contribute
by mmazlan67
on Jul 20, 2017 at 04:55

    Hi, i am working on a simple perl script to grab 3 variables based on a textfile. I am using regex. I tried to catch the word after the match string for the first variable, it works fine. But when i tried on the second variables, it appears error: Use of uninitialized value in print at enhancement.pl line 31, <$readhandle> line 4. I tried to put no warnings 'uninitialized';, but still the second output did not appear as expected. From the output file, only the name which is blocka appear whereas the path did not. Below are my code and the text file used.

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; print "Enter the name of the file to read: "; my $filetoread = <STDIN>; chomp($filetoread); print "Enter the name of the file to write: "; my $filetowrite = <STDIN>; chomp($filetowrite); open my $readhandle, "<", $filetoread or die "Unable to read '$filetor +ead'"; open my $writehandle, ">", $filetowrite or die "Unable to write '$file +towrite'"; my $name; my $path; while (<$readhandle>) { if ($_=~ m/^Name=(\S+)/) { $name = $1; print $writehandle $name; } if ($_=~ m/^Path=(\S+)/) { $path = $2; print $writehandle $path; } } close $readhandle; close $writehandle;

    This is the textfile used

    Name= blocka Path=/main/sub/a/bg/adee/swarfrw/ewqsx/fewaxr/akeil/awedr/date/file
do something if hash keys match regex
4 direct replies — Read more / Contribute
by anandk
on Jul 20, 2017 at 04:03

    O wise monks, greetings. I'm trying to replace the values of a hash based on the keys matching a regex. Is there a more compact, one liner way of doing it, without using foreach and the braces ? Most ideally I would want something like this:

    $hash{/abc_(.*)_ghi/} = boom_$1
    That should reassign all the 4 key-value pairs in the hash.

    My current code:
    use Data::Dumper; my %hash = ( xxx_text10_yyy => 1, xxx_text11_yyy => 1, mmm_text12_nnn => 1, mmm_text13_nnn => 1, abc_text6_ghi => 1, abc_text7_ghi => 1, abc_text8_ghi => 1, abc_text9_ghi => 1 ); print Dumper(\%hash); foreach my $key (keys %hash) { $hash{$key} = "boom_$1" if ($key =~ /abc_(.*)_ghi/); $hash{$key} = "doom_$1" if ($key =~ /mmm_(.*)_nnn/); } print Dumper(\%hash);
Value of a key in hash in hex
2 direct replies — Read more / Contribute
by PSP
on Jul 20, 2017 at 03:12

    print $sqlexecinfo; shows 1677721807/20/2017 00:03:38 while print $sidstat{$instsid}; shows HASH(0x2017b98) why is the difference?

    open(SQLPLUS,"$CMD|") or die "Could not start SQLPLUS"; while (<SQLPLUS>) { chomp; my ($instsid,$sqlexecinfo)=split '=>'; $sidstat{$instsid}{SQLEXECINFO}=$sqlexecinfo; print $sqlexecinfo; print $sidstat{$instsid}; } debug(scalar(keys %sidstat)." session state recorded.\n"); return \%sidstat;
How to replace empty values with value in previous array
4 direct replies — Read more / Contribute
by Fshah
on Jul 20, 2017 at 02:29
    hello monks,

    I have an array which is joined by ';' In the next loop I get empty values I want to find the empty values and replace them by the one's obtained in the previous loop

    @first_loop=(1668;1733;60;32;3173;0;2517;58221;55764;0;0;0;0;Td;30720; +1;9;25;0;2; Carry 0); @next_loop=(1671;1661;0;0;;;0;0;0;0;;;;;;1;9;25;0;2; Carry 1);

    I want the output in the present array to not have empty values instead have previous value

    thank you for the help in advance edit: I have an array of such data in each line I want to perform this operation on entire array
    1668;1733;60;32;3173;0;2517;58221;55764;0;0;0;0;Td;30720;1;9;25;0;2; C +arry 0 1671;1661;0;0;;;0;0;0;0;;;;;;1;9;25;0;2; Carry 1 1671;1661;;0;;;0;0;0;0;;;;;;1;9;;0;2; Carry 2
DNA Pattern Matching
1 direct reply — Read more / Contribute
by Speed_Freak
on Jul 19, 2017 at 17:50

    The basics: I'm new to this, and I've gotten myself so far down a rabbit hole that my mind is going blank. I have searched for the basics on pattern matching, phoned a friend, and tried venturing into the BioPerl world, but can't wrap my head around the solutions involving C, or using Hex. (Also, the BioPerl How To's seem to be broken?)

    The layout: I have a database with multiple tables that I am working with. One of the tables contains a list of pairs (pairs of consensus sequences and their mismatch.) These pairs correspond to ID's in another table. And those ID's correspond to sequences in a third table.

    So far, (with the extensive help of a colleague) I have a script that looks through the list of pairs and finds both sequences by their id and their corresponding mismatches in the ID table (four sequence id's in total.) The script then matches those ID's with their sequences in the sequence table. I have also gone as far as to identify the central base for each sequence. (Each sequence is 25 bases in length, and I have filtered the results to only find sequences that are exactly 25 bases long.)

    The problem: For each sequence, there is only one potential mismatch listed in the database. I need to find out if the other two sequences exist in the database. If my (shortened for simplicity) sequence was ACTGCCT, I would call this my pm_seq. It's identified mismatch (mm_seq) might be ACTACCT. But the sequence table itself may contain up to two more mismatches. (ACTCCCT and ACTTCCT.) I need to search each of my identified pm_id's seqences against the entire sequence list and identify the id's of all three possible mismatches. One attempt at this has been to set a pattern for the sequence like so: my $pattern = ($ppi_pm_seq =~ /(CAGT{12})(CAGT{1})(CAGT{12})/). But I am lost when it comes to searching against my sequence table and identifying sequence ID's that have a sequence that matches $1 AND $3.

    Ultimately I am looking to generate an output that contains each sequence, and up to three mismatches that differ at the central base for a large list of target sequences. The code below is later in the script, but it fetches the sequences for the identified pairs. (one pm and one mm per pair.) But I still need to search the entire sequence set for the other two possible mm's. (I think it will be easier to search for all 3 possible mm's based on the pm sequence rather than identify the known mm and search for the other two.)

    #perl 5.8.8 #code to get data from database not included my $ppiquery1 = "select sequence from seq_table where seq_id = $ppi_pm +_id AND LENGTH(seq) = 25"; my $ppiquery2 = "select sequence from seq_table where seq_id = $ppi_mm +_id AND LENGTH(seq) = 25"; my $mpiquery1 = "select sequence from seq_table where seq_id = $mpi_pm +_id AND LENGTH(seq) = 25"; my $mpiquery2 = "select sequence from seq_table where seq_id = $mpi_mm +_id AND LENGTH(seq) = 25"; my @row3 = $dbh->selectrow_array($ppiquery1); unless (@row3) { die "No seq for $ppi_pm_id?\n"; } my @row4 = $dbh->selectrow_array($ppiquery2); unless (@row4) { die "No seq for $ppi_mm_id?\n"; } my @row5 = $dbh->selectrow_array($mpiquery1); unless (@row5) { die "No seq for $mpi_pm_id?\n"; } my @row6 = $dbh->selectrow_array($mpiquery2); unless (@row6) { die "No seq for $mpi_mm_id?\n"; } my ($ppi_pm_seq) = @row3; my ($ppi_mm_seq) = @row4; my ($mpi_pm_seq) = @row5; my ($mpi_mm_seq) = @row6;

    Beyond here, I've attempted to set the pattern with ($ppi_pm_seq =~ /(CAGT{12})(CAGT{1})(CAGT{12})/) and then use a series of if/elsif for each of the four possible combinations of $2 (A, C, T, G) to store the seq_id's for each group....to no avail. Any guidance would be greatly appreciated. I'd like to stay completely in perl if possible, mostly because I barely grasp this let alone something new!

CPAN module compile error: LWP::Curl
2 direct replies — Read more / Contribute
by fireblood
on Jul 19, 2017 at 17:39
    Dear Monks,

    I am trying to add LWP::Curl to my library of installed CPAN modules. When I initiate the process to fetch it and process it into my library, I see a message that says:
    Package libcurl was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libcurl.pc'
    to the PKG_CONFIG_PATH environment variable
    after which the process fails. I've downloaded curl both for Windows and for Cygwin directly from the source, https://curl.haxx.se/download.html, but have not seen the libcurl.pc file in either of them.
    After doing much web searching, I've found that others have been encountering this since around 2008. However, I haven't found any posts that provide a solution.

script to stop veritas volume manager
1 direct reply — Read more / Contribute
by dnyan_linux
on Jul 19, 2017 at 11:57

    Hi,

    I am new to perl and trying to write script which will verify first if veritas volume manager is running. if it is running then stop it and print the output veritas volume manager has stopped.

    i wrote below code but not able to print it like " volume <volume name> has stopped.

    #verify volume is in running state #!/usr/local/bin/perl @list = ("vxinfo -g <diskgroup name> <volumename>","vxinfo -g <diskgr +oup name> <volumename>" "); # foreach loop execution foreach $a (@list){ $result = `$a`; print "output of command $a is $result\n"; }

    i need to check here if volume is running then stop it else print error. but i am not able to write code. also in above section it is printing output of commnad is. i need output "status of volume is :"

    print "stopping the volume\n"; $vol1 = `vxvol -g <diskgroup name> stop <volumename>`; $vol2 = `vxvol -g <diskgroup name> stop <volumename>`;

    need code for verify voulume is stopped and print it like "volume <volume name > has stopped"

Telnet command with more than 1024 chars
2 direct replies — Read more / Contribute
by ElectricCheese
on Jul 19, 2017 at 09:39

    I'm seeking knowledge to guide me through this dense mist...

    I discovered the telnet server on which I connect (Windows Server (probably 2013)), any command sent must have at maximum 1024 characters, anything more than this, the server asks me for "More? ", and then I should input the remaining characters and press enter. So far, so good.

    I have a program written in Perl, that executes a series of commands in this server, but recently some commands have been stuck until it times out, and I discovered that are the commands with more than 1024 characters.

    So, I decided to rewrite the execution function to support this behavior, but any one of methods tried didn't worked.

    This is how I normally execute my commands before:

    my $t = new Net::Telnet(Telnetmode => 1, Errmode => 'return'); $t->prompt('/C:\\\\(.*)>/i'); $t->open(Host => '192.168.0.10'); $ok = $t->login('myUsername', 'myPassword'); my $cmd = "blah blah blah (...)"; # 1287 characters of a VALID comm +and my @r = $t->cmd(String => $cmd, Timeout => 60);

    This will result in timeout. If the command have at maximum of 1024 characters, it passes normally.

    Then I decided use this way, instead of  $t->cmd()

    my @r = $t->print(String => $cmd, Timeout => 60); ($prematch, $match) = $t->waitfor(String => 'More? ', Timeout=>60) +or die("MORE NOT FOUND");

    And the waitfor times out... I'm pretty lost here.

    So my questions are:

    1) Am I missing anything about telnet and the limitation of 1024 input characters? So maybe this could be solved by using a different configuration? I have googled a lot about this subject and found't anything useful...

    2) Is the commands $t->print() and $t->waitfor() right?

    Where do we go from here?

    Thanks for your help monks!


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 the sunlight beams...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (2)
    As of 2017-07-23 13:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I came, I saw, I ...
























      Results (347 votes). Check out past polls.