http://qs321.pair.com?node_id=479

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
[OT] Filtering / Highlighting serial port input / PuTTY output
2 direct replies — Read more / Contribute
by afoken
on Aug 13, 2020 at 11:24

    Hi!

    I'm working with two systems, both without real(TM) operating systems. One is a microcontroller, running our software on bare metal, the other is my PC running Windows 7. The microcontroller writes debug output to one of its serial ports, which is connected to the PC. On the PC, putty simply displays whatever text is written to the debug port. A common setup at work, but I'm drowning in debug output. All of it is kind-of relevant, but usually only a little bit of the debug output is relevant for the current problem.

    (And no, I can't disable the irrelevant debug output on the microcontroller in reasonable time.)

    On a real operating system, I would run something like this:

    stty raw 115200 < /dev/ttyS0 grep --perl '^(Foo|Bar):' < /dev/ttyS0

    But I'm stuck on Windows. I need some way to print input from a serial port to a fully resizeable window, optionally with a filter that either omits or highlights incoming lines. PuTTY does all I need, except for filtering. Trying to run anything perl in a command window already fails, because the console window has a maximum width of 80 characters, which is little more than a third of the screen width.

    And I don't have the time to hack a special version of PuTTY or a large perl application.

    A Google search for "putty filter" and similar combinations results in lots of ugly teapots, anti-glare filters, and some other wierd stuff, but nothing even close to filtering output from PuTTY.

    Any hints? E.g. how to get that !%&%$*! standard console window to allow free resizing? Or a tool that can do what I want?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
pass one or more directories into a file and use that as INPUT to a called script
3 direct replies — Read more / Contribute
by noviceuser
on Aug 13, 2020 at 10:46

    i want to write a piece of code say comp.pl where i can pass one or more comma separated directories into a file and use that as INPUT to a called script runTest.pl .

    here, directories contains multiple files having testcases

    below, $runPath -> path for testcases file / directory containing such file

    $runTest -> command line passed testcases file or command line passed directory where such multiple testcases files exist

    my $testFile = ''; if (-f "$runPath/$runTest") { $testFile = "$runPath/$runTest"; } else { open (my $RF, '>', 'testFile'); print {$RF} map { "$_\n" } split(/,/, $runTest); close $RF; $testFile = "$runPath/$testFile"; } $status += utils::execCommand(Command => "$runTest.pl -f $testFile;

    the above $status line is working fine when passing testFile from command line but not working when passing directory/directories.

    example: comp.pl --runTest testDirectory1, testDirectory2

    so when i am executing the comp.pl script, it is not reading the files and its listed testcases under testDirectory1 and testDirectory2. it is just printing testDirectory1 and testDirectory2 line by line inside <testFile>

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.


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.