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
SSL connect attempt failed
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 12, 2020 at 12:49
    Hi Monks!

    Is there a way to pass a new SSH server host keys since it was changed in the host server or to update this key from a Perl scrip using Net::FTPSSL.
    When my Perl script runs it gives this error message:

    "Can't open xxx.xxx.xxx.xxx: SSL connect attempt failed"

    Posting a test code here which gives the same error. If I use Filezilla, it detects that the server key was changed, asks to accept the new key and connects, but from the Perl script, it doesn't, I guess I have to send a flag or the key it sefl in the code, thats where my problem is, any suggestions?

    Test Code:
    #!/usr/bin/perl use strict; use warnings; use Net::FTPSSL; open (STDERR, "> logfile.txt"); # Redirects STDERR to this file. my %connectionHash = ( Port => 21, Encryption => 'E', Debug => 1, OverridePASV => 'xxx.xxx.xxx.xxx', Croak => 0, PreserveTimestamp => 0, ); my %sslHash = ( #SSL_cert_file => '', #SSL_reuse_ctx => '', SSL_key_file => 'MD5:9f:...f9', #SSL_ca_file => '', #SSL_use_cert => 1, ); $connectionHash{SSL_Client_Certificate} = \%sslHash; my $ftps = Net::FTPSSL->new( 'xxx.xxx.xxx.xxx:', %connectionHash, ); $ftps->login ('user', 'pass') or warn "Could not login to xxx.xxx.xxx +.xxx: ", $ftps->message; $ftps->nlst(); $ftps->quit();

    Thanks for looking!
Using Gmail - making my application secure
1 direct reply — Read more / Contribute
by Arik123
on Aug 12, 2020 at 07:42

    Hi, monks!

    I wrote an application that uses Gmail (IMAP and SMTP), using modules I found on CPAN (Email::Send::SMTP::Gmail and Net::IMAP::Simple::SSL). It works... only that Gmail complains that my application is insecure, and wants me to configure my account to allow access for insecure applications.

    Is it possible wo access Gmail in a way it'll be happy? to write a secure application in Perl?

    Thank you very much!

Call function no more than every 0.1 seconds
8 direct replies — Read more / Contribute
by zapoi
on Aug 11, 2020 at 19:11

    Dear gracious ones,

    I'm trying to write a loop that will call a function no more frequently than every 0.1 seconds. The function has an embedded API call so I can't be certain how long it will take to return but typically about 0.03 seconds. I currently do this by waiting 0.07 seconds but this isn't what I require. I want my loop to wait until exactly 0.1 seconds since last execution. I require the data from the last execution so if the last execution took 0.2s then I need to wait for it to complete, I can't concurrently call the function

    Any ideas?

    Thank you

    Zapoi
putting commas separated values into a new file line by line
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 11, 2020 at 12:08

    from command line, we are passing multiple values separated by commas such as sydney,delhi,NY,Russia. these values are getting stored under $runTest in the script. now i want to create a new file with contents of $runTest but as line by line. example

    INPUT (contents of $runTest): sydney,delhi,NY,Russia OUTPUT (under new file: myfile): sydney delhi NY Russia
(OT) Komodo with Perl and Python
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 11, 2020 at 04:32

    Hello,

    I use Komodo (11) with Perl for years, now i'm also trying to use Komodo for Python.

    I've tried to add Python paths into Komodo and Komodo says there's no Python interpterer.

    Before I try to "graduate" on setting up Python I probably have to ask this:

    Can Komodo work with Perl and Python at the same time?

    Once both Perl and Python are "found" by Komodo I expect to run Perl or Python scripts without Komodo complaining.

    Sorry about my question, it probably even doesn't belong here.

    Thanks for your help.

    MaSk

    2020-08-12 Retitled by GrandFather, as per Monastery guidelines

all permutations of given lenght
4 direct replies — Read more / Contribute
by cataclismic_user
on Aug 11, 2020 at 03:11
    Dear Perl Monks,

    I am a novice of Perl. My question is rather simple: how can I generate all permutations of a set of characters, with a given length, in an computationally efficient manner?

    To further explain my conundrum: I have a large list of elements such as O=C(O)C(N)CCC/N=C(\N)N, O=C(N)C[C@H](N)C(=O)O, O=C(O)[C@@H](N)Cc1cncn1 and so on. I want to generate all possible permutations, including repetitions of these strings, in a given length (for ex. 6).

    Thank you in advance!

What's going on in array element assignment?
2 direct replies — Read more / Contribute
by zapdos
on Aug 10, 2020 at 22:09
    So I'm following the book Learning Perl, there's this code with comments in it:
    $rocks[0] = 'bedrock'; $rocks[1] = 'slate'; $rocks[2]= 'lava'; $rocks[3] = 'crushed rock'; $rocks[99] = 'schist'; $#rocks = 2; # forget all rocks after 'lava' $#rocks = 99; # add 97 undef elements (the forgotten rocks are gone fo +rever)
    If I do print $rocks[$#rocks]; it prints nothing. Why? When I comment out $#rocks = 99; it prints 'lava' and when I comment out $#rocks = 2; it prints 'schist'. But when I maintain the two it prints nothing as I already said. And what the comments "add 97 undef elements (the forgotten rocks are gone forever)" and "forget all rocks after 'lava'" mean?
CPAN Module to determing overlap of 2 lists?
7 direct replies — Read more / Contribute
by wazat
on Aug 10, 2020 at 17:27

    I want to determine the overlap between the end of one list and the beginning of another. I have a quick brute force solution, but prefer to use an existing module if one is available. I didn't find one when I searched metacpan, but that doesn't mean it doesn't exist.

    # example @list1 = qw(a b c); @list2 = qw(b c d); # a b c # b c d # 1 2 list_overlap( \@list1, \@list2 ); # returns 2 @list1 = qw(a b c d b); @list2 = qw(b c d); # a b c d b # b c d # 1 list_overlap( \@list1, \@list2 ); # returns 1

    I don't know if this problem has a name.

    Intended use is to combine two bash_history files captured on different dates into a single bash_history file that doesn't duplicate the overlap between the files. (Yes, if I set HISTFILESIZE to -1, then bash would maintain an unlimited history file.

    __edit__ As pointed out, I should also specify that I want the largest overlap.

Why does default $_ only work
3 direct replies — Read more / Contribute
by catfish1116
on Aug 10, 2020 at 13:37

    I wrote a very simple script but dont understand why chomp($_ = <STDIN>) works and chomp(my $selection = <STDIN>) doesnt. Below is code written with chomp set to default.

    print "Enter a string that will match the secret matching pattern \n" +; chomp ($_ = <STDIN>); if ($_ = (/(.)\1/)) { print "The match was perfect \n"; } else { print

    TIA The Catfish

Not understanding while loop counting
5 direct replies — Read more / Contribute
by zapdos
on Aug 10, 2020 at 03:56
    $count = 0; while ($count < 10) { $count += 1; print "count is now $count\n"; }

    I don't get it. Why is it printing till 10 if the conditional expression asserts it should be less than (<) 10 and not less than or equal (<=) to 10? Shouldn't it print just till 9?


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.