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
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!

Can Perl do anything Java can do?
13 direct replies — Read more / Contribute
by MikeBraga
on Jul 19, 2017 at 07:01
    We want to create some applications and want to know the feasibility of using Perl.

    The other option is Java.

    We have these questions:
    (1.) Can Perl do anything Java can do?
    (2.) Can Perl be used to create web-applications like Amazon or Ebay? What is the HTTP and Application servers we can use then?
    (3.) Can Perl be used to create desktop applications, like can using Java swing?
    (4.) Can Perl be used to create a message broker applications, a FTP file transfer application, an e-mail sending and receiving application, or an ESB application?
Use 'use' in foreach
5 direct replies — Read more / Contribute
by zidi
on Jul 19, 2017 at 06:41
    Hey, I am currently storing some non core perl modules in an array like this:
    my @NotInstalledModules = ( 'Foo::Bar', 'Bar::Foo', )
    And I am able to install these modules (install, if eval("use $_") not possible...). The only problem is that I can't 'use' them afterwards. I tried:
    foreach (@Dependencies){ use $_; }
    which is not working. Any help is appreciated Best regards
Running script only within a specific domain/network
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 19, 2017 at 06:38

    Dear monks

    I want to allow a script to run only if it is physically inside a specific domain. Let's say that the script should work only if it is on a computer which is inside the network of the University of Wien (www.univie.ac.at). In order to do so, the script needs to read the network/domain in which the computer is (As you can see from the terms I am using, I am really a non-expert in all these IP & co. matters, but I am fairly okay in Perl programming ;). At the moment I can read the IP with the following:

    use warnings; use Net::Address::IP::Local; print my $address = Net::Address::IP::Local->public;

    Is the ip adress I am getting here stable enough to allow me to check if the computer is inside the university network over a longer period of time? If not, what is the best way to check it? Thanks

Issue with Net::SSH::Perl - can't establish connection
1 direct reply — Read more / Contribute
by dayton
on Jul 18, 2017 at 16:46
    Using Net::SSH::Perl and I can't establish a connection even though my key is accepted... what am I missing?
    .ssh/config:
    
    	Host remote.ssh.server
        	ControlMaster auto
        	ControlPath ~/.ssh/master-%r@%h:%p
        	User myusername
        	IdentityFile id_rsa
    

    The Code:

    $ssh = Net::SSH::Perl->new($host,debug=>true,options => ["ConnectT +imeout=5","StrictHostKeyChecking=no"]); $ssh_conf="$ENV{'HOME'}/.ssh/config"; $cfg = Net::SSH::Perl::Config->new($host); $cfg->read_config($ssh_conf); if (! $USERNAME){ $USER=$cfg->get('user'); } eval{$ssh->login($USER);}; if ($@){ print "Unable to connect to $host\n$@\n"; } eval{($out, $err, $exit)=$ssh->cmd($exec_cmd);};print "Unable to e +xecute: $exec_cmd\n" if $@; ### print "\n\nmade it this far\n\n"; ### if ($out){ print $out; } else { print "$err\n$exit"; }

    result:

    local.host: Reading configuration data /home/myusername/.ssh/config
    local.host: Reading configuration data /etc/ssh_config
    local.host: Connecting to remote.ssh.server, port 22.
    local.host: Remote version string: SSH-2.0-OpenSSH_7.2
    local.host: Remote protocol version 2.0, remote software version OpenSSH_7.2
    local.host: Net::SSH::Perl Version 2.09, protocol version 2.0.
    local.host: No compat match: OpenSSH_7.2.
    local.host: Connection established.
    local.host: Sent key-exchange init (KEXINIT), waiting for response.
    local.host: Using curve25519-sha256@libssh.org for key exchange
    local.host: Host key algorithm: ssh-ed25519
    local.host: Algorithms, c->s: chacha20-poly1305@openssh.com <implicit> none
    local.host: Algorithms, s->c: chacha20-poly1305@openssh.com <implicit> none
    local.host: Generating ephemeral key pair.
    local.host: Entering Curve 25519 Key Exchange.
    local.host: Sent client public key, waiting for reply.
    local.host: Received host key, type 'ssh-ed25519'.
    local.host: Host 'remote.ssh.server' is known and matches the host key.
    local.host: Verifying server signature.
    local.host: Send NEWKEYS.
    local.host: Waiting for NEWKEYS message.
    local.host: Enabling encryption/MAC/compression.
    local.host: Sending request for user-authentication service.
    local.host: SSH2_MSG_EXT_INFO received
    local.host: SSH Extension activated: server-sig-algs=rsa-sha2-256,rsa-sha2-512
    local.host: Service accepted: ssh-userauth.
    local.host: Trying empty user-authentication request.
    local.host: Authentication methods that can continue: publickey,gssapi-keyex,gssapi-with-mic,password.
    local.host: Next method to try is publickey.
    local.host: Publickey: testing agent key '/home/myusername/.ssh/id_rsa'
    local.host: Public key is accepted, signing data.
    local.host: Key fingerprint: SHA256:rScQOC1zgitfa/IiDb7CYwPkwK/k16ViRuAfzv4ITcQ=
    Unable to connect to remote.ssh.server
    Error reading response length from auth socket. at /usr/local/lib64/perl5/Net/SSH/Perl/Auth/PublicKey.pm line 104.
    
    local.host: channel 0: new client-session
    local.host: Requesting channel_open for channel 0.
    local.host: Entering interactive session.
    
    
    made it this far
    ]$
    

    just using "ssh -v":

    ]$ ssh -v remote.ssh.server "uptime"
    OpenSSH_7.5p1, OpenSSL 1.1.0f-fips  25 May 2017
    debug1: Reading configuration data /home/myusername/.ssh/config
    debug1: /home/myusername/.ssh/config line 8: Applying options for remote.ssh.server
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Reading configuration data /etc/ssh/ssh_config.d/05-redhat.conf
    debug1: Reading configuration data /etc/crypto-policies/back-ends/openssh.config
    debug1: /etc/ssh/ssh_config.d/05-redhat.conf line 8: Applying options for *
    debug1: auto-mux: Trying existing master
    debug1: Control socket "/home/myusername/.ssh/master-myusername@remote.ssh.server:22" does not exist
    debug1: Connecting to remote.ssh.server xxx.xxx.xxx.xxx port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file id_rsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file id_rsa-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.5
    debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2
    debug1: match: OpenSSH_7.2 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to remote.ssh.server:22 as 'myusername'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256@libssh.org
    debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    debug1: kex: server->client cipher: aes256-gcm@openssh.com MAC: <implicit> compression: none
    debug1: kex: client->server cipher: aes256-gcm@openssh.com MAC: <implicit> compression: none
    debug1: kex: curve25519-sha256@libssh.org need=32 dh_need=32
    debug1: kex: curve25519-sha256@libssh.org need=32 dh_need=32
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ecdsa-sha2-nistp256 SHA256:b0EOVxSO46RlNAPAeDQg66CnCsKupSxhB1Kl5ihJ9Ok
    debug1: Host 'remote.ssh.server' is known and matches the ECDSA host key.
    debug1: Found key in /home/myusername/.ssh/known_hosts:3
    debug1: rekey after 4294967296 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: rekey after 4294967296 blocks
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
    debug1: Next authentication method: gssapi-keyex
    debug1: No valid Key exchange context
    debug1: Next authentication method: gssapi-with-mic
    debug1: Unspecified GSS failure.  Minor code may provide more information
    No Kerberos credentials available (default cache: KEYRING:persistent:1000)
    
    debug1: Unspecified GSS failure.  Minor code may provide more information
    No Kerberos credentials available (default cache: KEYRING:persistent:1000)
    
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /home/myusername/.ssh/id_rsa
    debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
    debug1: Authentication succeeded (publickey).
    Authenticated to remote.ssh.server (xxx.xxx.xxx.xxx:22).
    debug1: setting up multiplex master socket
    debug1: channel 4: new /home/myusername/.ssh/master-myusername@remote.ssh.server:22
    debug1: channel 5: new client-session
    debug1: Entering interactive session.
    debug1: pledge: id
    debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
    debug1: Requesting X11 forwarding with authentication spoofing.
    debug1: Requesting authentication agent forwarding.
    debug1: Sending environment.
    debug1: Sending env LANG = en_US.utf8
    debug1: Sending env XMODIFIERS = @im=none
    debug1: Sending command: uptime
    debug1: client_input_channel_req: channel 5 rtype exit-status reply 0
    debug1: client_input_channel_req: channel 5 rtype eow@openssh.com reply 0
     15:23:01 up 50 days, 19:36,  1 user,  load average: 0.45, 0.25, 0.24
    debug1: channel 5: free: client-session, nchannels 6
    debug1: channel 0: free: port listener, nchannels 5
    debug1: channel 1: free: port listener, nchannels 4
    debug1: channel 2: free: port listener, nchannels 3
    debug1: channel 3: free: port listener, nchannels 2
    debug1: channel 4: free: /home/myusername/.ssh/master-myusername@remote.ssh.server:22, nchannels 1
    Transferred: sent 2744, received 2564 bytes, in 0.1 seconds
    Bytes per second: sent 27909.5, received 26078.7
    debug1: Exit status 0


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?
    [perldigious]: jedikaiti: Breakout your Gustav Holst Recordings.
    [jedikaiti]: :-)

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (13)
    As of 2017-07-24 15:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I came, I saw, I ...
























      Results (355 votes). Check out past polls.