perl - Why do I have to send multiple messages to my Jabber bot before it will logout?

I am trying to make my own Jabber bot but i have run into a little trouble. I have gotten my bot to respond to messages, however, if I try to change the bot's presence then it seems as though all of the messages you send to the bot get delayed. What I mean is when I run the script I change the presence so I can see that it is online. Then when I send it a message it takes three before the callback subroutine I have set up for messages gets called. After the thirrd message is sent and the chat subroutine is called it still process the first ...Read more

authentication - how to automate ssh login where 2 passwords is required for user with perl script

I need to automate a test case where user,on ssh login, is prompted for 2nd password if user is authenticated successfully with 1st password (which is keyboard interactive).How to automate this test case using perl ? Have tried using perl SSH expect module but it only works for 1st password : Without Enter your EMERG one-time password line, script works for single password. But if I include 2nd password ie. Enter your EMERG one-time password , following error is seen on compilation : syntax error at line 8, near "time password"G...Read more

n gram - How to get the array of all ngrams in Perl Text::Ngrams

As you know the module Text::Ngrams in Perl can give Ngrams analysis. There is the following function to retrieve the array of Ngrams and frequencies.get_ngrams(orderby=>'ngram|frequency|none',onlyfirst=>NUMBER,out=>filename|handle,normalize=>1)But it gives only the last Ngrams. For example the following code does not give both Uni-Gram and Bi-Gram:my $ng3 = Text::Ngrams->new( windowsize => 2, type=>'byte');my $text = "test teXT TESTtexT";$text =~ s/ +/ /g; # replace multiple spaces to single$text = uc $text; # uppercase al...Read more

perl - Extract substring using two delimiters and NO REGEX

I have a function whose aim is to extract a substring found between two delimiters. I would use regex but in this case I have explicit instructions not to use them.I had a simpler and more elegant solution which was just one line but I cannot for the life of me remember or find it.sub findBetween {my ($theString,$delimiter1,$delimiter2) = (@_);my $tmp = substr($theString, index($theString,$delimiter1)+length($delimiter1));$tmp = substr($tmp, 0, index($tmp,$delimiter2));return $tmp;}Thank you for taking a look at this issue, I am aware it is ver...Read more

split - Perl autosplit with non-file arguments

I'm trying to create a perl script that autosplits the STDIN, and then does something to column X. But I want the column to be passed by argument to the script. However, apparently, when I invoke perl with the autosplit flag, it switches to a mode where it tries to implicitly open the "files" defined in the command line arguments, even though my arguments aren't files.Example:my $column = shift;while(<STDIN>) { print "F $column: $F[$column]!\n";}Then I try to run it with argument 2 to print the 2nd column:$ echo -e "1 22\n2 33\n3 55"...Read more

perl - split a line into its components

I need to split the lines of an input file into its columns. ATOM 0 HB3 ALA C 999 28.811 -7.680 12.279 1.00 57.53 H ATOM 7637 N PRO C1000 27.299 -5.667 10.647 1.00216.82 NThe code I have works fine, as long as the 6th column is <1000, or shorter than 4 digits:($ATOM, $atom_num, $atom_type, $res, $chain, $res_num) = split(" ", $pdb)However as soon as column 6 reaches 1000, it will no longer discriminate the two columns. I am no expert in perl, but the code I am dealing with is perl, so I need t...Read more

perl - Reading from a textfile and putting information into an array

I'm trying to calculate the GCD of true random numbers using and grabbing those numbers from a text file. Here is a program to do the above with a PRNG that I created earlier.#!/usr/bin/perluse strict;use warnings;my $range = 100;my $gcdcount = 0;sub gcd_iter($$) { my ($u, $v) = @_; while ($v) { ($u, $v) = ($v, $u % $v); } return abs($u);}for (my $count=0; $count<=5000; $count++) { my $random_numx = int(rand($range)); my $random_numy = int(rand($range)); my @pair = ($random_numx, $random_numy); if (gc...Read more

Using perl to split over multiple lines

I'm trying to write a perl script to process a log4net log file. The fields in the log file are separated by a semi-colon. My end goal is to capture each field and populate a mysql table.Usually I have lines that look a little like this (all on a single line)DEBUG;2017-06-13T03:56:38,316-05:00;2017-06-13 08:56:38,316;79ab0b95-7f58-44a8-a2c6-1f8feba1d72d;(null);WorkerStartup 1;"Starting services."These are easy to process. I can simply split by semicolon to get the information I need.However occassionally the "message" field at the end may span ...Read more

Perl `split` does not `split` to default array

I have this strange problem with split in that it does not by default split into the default array.Below is some toy code.#!/usr/bin/perl$A="A:B:C:D";split (":",$A);print $_[0];This does not print anything. However if I explicitly split into the default array like#!/usr/bin/perl$A="A:B:C:D";@_=split (":",$A);print $_[0];It's correctly prints A. My perl version is v5.22.1....Read more

N-Gram, tf-idf and Cosine similarity in Perl

I am trying to do some pattern 'mining' in piece of multi word on each line. I have done the N-gram analysis using the Text::Ngrams module in perl which give me the frequency of each word . I am however quite confused about the finding patterns in this text.The tf-idf finds frequency also I presume but how does this differ from the Ngram analysis that I did and how does the similarity measure also help.Please are there any perl modules or snippets of code I could get to understand some of this concepts .Please I am from a physics background b...Read more

What's the safest way to iterate through the keys of a Perl hash?

If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys? I have heard that using each may in some way have unintended side effects. So, is that true, and is one of the two following methods best, or is there a better way?# Method 1while (my ($key, $value) = each(%hash)) { # Something}# Method 2foreach my $key (keys(%hash)) { # Something}...Read more

perl - How do you loop and match column 1 and 2 of file1 with cell in column1 of file2 in order to replace them with the adjacent cell in column 2 of file 2?

I am using String-db interactions for a project but I found out that the complete list of interactions uses their ensembl protein IDs. I would like to replace those ensembl protein ID names with their HGNC approved gene symbols. Using BioMart, I downloaded a table with the ensembl protein IDs and their respective gene name. So I need to match all the ensembl IDs found in the string file (both first and second column have ensembl IDs) with their ensembl ID in my biomart file and then replace each ID with their gene symbol found, also, in the bio...Read more

Can you force either a scalar or array ref to be an array in Perl?

I have a perl variable $results that gets returned from a service. The value is supposed to be an array, and $results should be an array reference. However, when the array has only one item in it, $results will be set to that value, and not a referenced array that contains that one item.I want to do a foreach loop on the expected array. Without checking ref($results) eq 'ARRAY', is there any way to have something equivalent to the following:foreach my $result (@$results) { # Process $result}That particular code sample will work for the re...Read more