Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

poll ideas quest 2020
Starts at: Jan 01, 2020 at 00:00
Ends at: Dec 31, 2020 at 23:59
Current Status: Active
5 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

CGI URL simple
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 21, 2020 at 13:23


    I have a very naive question about CGI. I have a small CGI script that generates a basic HTML page. The script is called by a URL such as

    Everything works fine. What I do not like is that in the URL bar I see this monster URL ( Is there any way to maybe reduce it to or something similar (of course without changing page)?

selectrow_array installation
2 direct replies — Read more / Contribute
by AjayUSAPerl
on Feb 20, 2020 at 23:30
    I'm using PERL Web application programs that have been built for and distributed by our organization. It has been working properly on a LiquidWeb installation running cPanel 76.0.22 Linux system. I'm now ported the same code base into another installation running on GoDaddy running cPanel 78.0.38 Linux system. The application works fairly well except at a crucial place. After much tracing, I found that the 'selectrow_array() always returns an empty list. If I use individual prepare-execute-fetch calls, it works. Of course, I don't want to change the code all over the place because selectrow_array is used everywhere. The Perl modules are installed by default by GoDaddy and I can make changes if I knew what to change. Anybody seen this type of error and what am I missing in the installation? Thanks Ajay
Generating a CRC-16/XMODEM checksum in Hex
1 direct reply — Read more / Contribute
by Djinni
on Feb 20, 2020 at 12:37

    I am trying to generate a a CRC-16/XMODEM checksum. I have been using: and as a guide. As well as Digest/ however I have been unable to get the perl module Digest::CRC to give me the expected result.

    #!/usr/bin/perl -w use strict; use Digest::CRC qw(crc64 crc32 crc16 crcccitt crc crc8 crcopenpgparmor +); my @s=( { 's'=>"9848C503738276ADCA02BF5DC1A3ABF2", 'crc16'=>"9F4B" }, { 's'=>"841374844ADDF4A36CEDB127C82086B9", 'crc16'=>"408E" }, { 's'=>"8AC1070ACD1659BB4F507191E33F7AD4", 'crc16'=>"E1E3" }, { 's'=>"34623A01DCDA35BED462953B4E2458DA", 'crc16'=>"7B40" }, { 's'=>"E29107CB32975E859D76A885BF57BE35", 'crc16'=>"2B92" }, { 's'=>"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 'crc16'=>"0041" }, ); # width=16 poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0 +000 check=0x31c3 residue=0x0000 name="CRC-16/XMODEM" my $width = 16; my $init = 0x0000; my $xorout = 0x0000; my $refout = 0; my $poly = 0x1021; my $refin = 0; my $cont = 0x31c3; for my $tv (@s) { my $crc16 = crc($tv->{s},$width,$init,$xorout,$refout,$poly,$refin +,$cont); print qq{ Input was: $tv->{s} crc: $crc16 -- Should be: $tv->{crc16} }; }
    I have another issue in that I do not understand what "cont" is here.
Strange interaction between print and the ternary conditional operator
6 direct replies — Read more / Contribute
by WingedKnight
on Feb 19, 2020 at 22:17

    Ran into a strange interaction between print and the ternary conditional operator that I don't understand. If we do...:

    print 'foo, ' . (1 ? 'yes' : 'no') . ' bar';

    ...then we get the output...:

    foo, yes bar we would expect. However, if we do...:

    print (1 ? 'yes' : 'no') . ' bar';

    ...then we just get the output...:


    Why isn't " bar" getting appended to the output in the second case?

Using Parallel::ForkManager on multiple files using backtick operators for multiple files being processed simulnaneously
2 direct replies — Read more / Contribute
by symgryph
on Feb 19, 2020 at 13:30
    I have some code that essentailly runs a bash script sequentially, and was trying to multiprocess the managed children of the program. Aka, I use perl to run program x on y # of files. I use it as an orchestrator. When I try to run on multiple files, I get two running processes with the same filename, instead of two processes running on two different filenames. I am not sure on how to make my code multi-process aware, and need some help. Here is my code.
    #!/usr/bin/env perl -w use Parallel::ForkManager; my $filename = 'all.txt'; my $failuresfilename="failed.tsv"; open (my $target, "<", $filename) or die "Cannot open < $filename: $!" +; open (my $failures, ">", $failuresfilename) or die "Cannot open > $fai +luresfilename: $!"; sub readinFile { @lines = <$target>; } sub execute { $multiprocess = Parallel::ForkManager->new(2); TARGETS: foreach $processme (@lines) { $multiprocess->start and next TARGETS; chomp $processme; $command="cfn_nag_scan -o json --input-path $processme > $processm +e_.cfnag.json"; `$command`; $multiprocess->finish; } } sub findFailures { @files=`find ./ -iname "*cfnag*"`; $jqcommand='jq --raw-output \'.[] | select (.file_results.failure_co +unt > 0) |[.filename, .file_results.failure_count] |@tsv\''; foreach (@files) { chomp; s/\/\//\//g; @a=`cat $_ |$jqcommand`; print $failures @a; } } readinFile(); execute(); #findFailures(); close $failures; close $failuresfilename;
    The subroutine in question is 'execute'. Any help would be appreciated. My input is a bunch of filenames that come from the 'find' command (in this case things I want to scan with cfn_nag). The system sub-executes cfn_nag_scan from the filenames array, which in turn system's the cfn_nag which outputs a bunch of 'scan' result files. Perl is more of a dispatcher than a processor of data.
    "Two Wheels good, Four wheels bad."
Optimizing a CHI-based data throttler
4 direct replies — Read more / Contribute
by perlancar
on Feb 19, 2020 at 00:53

    I'm experimenting on using CHI as the backend of a Data::Throttler-like module. The speed is not great: my module is becoming linearly slower as the max_items parameter is increased: it's about 3 times slower than Data::Throttler with max_items=100, and 20 times slower with max_items=1000. Any idea on how to close the gap, or is my endeavor with CHI in this case a lost cause?

    package Data::Throttler_CHI; use strict; use warnings; sub new { my ($package, %args) = @_; bless \%args, $package; } my $counter = 0; sub try_push { my $self = shift; my $now = time(); $counter++; $counter = 0 if $counter == 2e31; # wraparound 32bit int $self->{cache}->set("$now|$counter", 1, $self->{interval}); # Y228 +6! my @keys0 = $self->{cache}->get_keys; my @keys; for my $key (@keys0) { my ($key_time, $key_serial) = split /\|/, $key, 2; if ($key_time >= $now - $self->{interval}) { push @keys, $key; } } # these drivers return expired keys: Memory. so we need to purge t +hese keys my $do_purge = rand() < 0.05; # probabilistic $self->{cache}->purge if $do_purge && @keys < @keys0; return @keys <= $self->{max_items} ? 1:0; } 1;

    More complete code with documentation and tests is on CPAN: Data::Throttler_CHI.

Percentage of MS Windows Perl Users
7 direct replies — Read more / Contribute
by thechartist
on Feb 18, 2020 at 21:24

    I'm interested in improving the reliability of CPAN modules on systems that do not get all that much attention, and MSWin32 seems to be one of them.

    I have been studying the various CPAN testing documents, as well as checking out the CPAN testers log file, that gives the 1000 most recent reports.

    This is off-the-cuff and not rigorous, but a quick check for "Linux" gives me around 600 of test results, "BSD" around 360, and "MSWin32" around 40. This suggests to me (making certain assumptions that the testing population represents the broad user population) -- that only about 4% of Perl users are on Windows.

    Do those estimates seem at all accurate? Thanks for the guidance.

"print" of nonexistent element is actually altering a hash
5 direct replies — Read more / Contribute
by larrymenard
on Feb 17, 2020 at 13:11
    Monks, your responses to others have been very helpful to me for many years. Now however it is time to post my own question.

    I am creating a multi-dimensional hash and then printing a non-existent key in that hash. Curiously (at least to me), that "print" is actually altering the hash, adding an invalid (for lack of a better word) key.

    #!/usr/bin/perl use strict; use Data::Dumper; my %hash; $hash{'key1'}{'key2'} = 'value'; print "\nDump of \%hash (1):\n"; print Dumper \%hash; # This print statement is actually altering the hash print "\n\"$hash{'key0'}{'key1'}{'key2'}\"\n"; print "\nDump of \%hash (2):\n"; print Dumper \%hash;
    The result is:
    Dump of %dtoHash (1): $VAR1 = { 'key1' => { 'key2' => 'value' } }; "" Dump of %dtoHash (2): $VAR1 = { 'key1' => { 'key2' => 'value' }, 'key0' => { 'key1' => {} } };

    The "print" statement is the only thing that can possibly be altering the hash. Indeed, comment it out and the 2nd dump is normal.

    I have reproduced this on multiple versions of perl 5, up to and including 5.26.3 (on CentOS 8).

    Why is the "print" statement altering the hash?

    Any explanation (or even better, advice on how to avoid it) would be much appreciated.

    Thanks in advance.

IO::Socket tutorial
2 direct replies — Read more / Contribute
by BernieC
on Feb 17, 2020 at 10:55
    I'm converting a program that uses sockets like file descriptors {it does a <$ssh> to read a line. UGH} to using sockets properly. And I can't find a clear tutorial. I know the command to send data in my new regime is send($socket, <stuff>, flags). But I've tried to chase down what the flags are. perldoc unhelpfully just says "Takes the same flags as the system call of the same name.". First off, that seems to presume that you have a unix handy to check on the system call. Second, what I found was
    $ man 2 send No manual entry for send in section 2
    so I have no clue what the flags do, but the tutorials seem to all give a value of 0. ??

    But my real interest in the switchover is to get reads to time out. I have a pokey host I connect to; sometimes {annoyingly regularly} the server seems to balk and my program just hangs, dead in the water, on the <$server>. So what I'd like to do is use the socket timeout mechanism to let my program continue. I see that there's a Timeout parameter that unhelpfully just says "Timeout value for various operations". ?? Units?? {I'd have guessed milliseconds, but IO::Socket says it is in seconds, which makes sense} which operations?? what happens when the timeout value is reached??

    Also, my incoming data is line-at-a-time and so the <$ssh> is perfect for what I need. Is there an equivalent way to do that with IO::Socket? I guess I could recv a character at a time until I got a newline.

error in POE::Component::Client::Telnet manpage?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 16, 2020 at 20:01
    In the POE::Component::Client::Telnet manpage it has a "sub result" with a typo in it.
    print STDERR join(' ', @{ $ref->{error} ) . "\n";
    should that be:
    print STDERR join(' ', @{ $ref->{error} } ) . "\n";
Find element in array
8 direct replies — Read more / Contribute
by Sofie
on Feb 16, 2020 at 07:36
    Hi I am very new to perl and struggling with simple things... I am trying to check if an input DNA sequence only contains nucleotides. And if it doesn't I want to print out the position in the sequence where an invalid character was entered. This is as far as I have come:
    #!/usr/bin/perl -w $DNA = <STDIN>; chomp ($DNA); @DNA = split ("", $DNA); $lengthseq = scalar @DNA; print "The length of the sequence is:\n", $lengthseq, "\n"; @nucleotideDNA = ""; #check if each element in array is nucleotide foreach $nucleotide (@DNA){ if ($nucleotide =~ /^[ATCG]+$/){ push @nucleotideDNA, $nucleotide; } else { push @nonvalid, $nucleotide; } }
    But how can I print the position of the non valid character? Not sure if this makes any sense.. Thanks
Perl in data science: could a grant from Perl foundation be useful?
2 direct replies — Read more / Contribute
by zubenel0
on Feb 18, 2020 at 14:15

    Recently I was thinking about if it is possible to make Perl a more attractive option for data science. I know that some great initiatives exist like RFC: 101 Perl PDL Exercises for Data Analysis or RFC: 100 PDL Exercises (ported from numpy). On my part, I will try to write a blog post with a particular machine learning task I have chosen. Nevertheless, as Ovid wrote falling short in data science field is a significant drawback of Perl. How to fix this?

    What I thought about as a way to to proceed could be a grant from Perl foundation. It could work only if it would be possible to find someone interested in a project related to Perl and data science and capable to do it. IMO one of the solutions that could help would be to write a book on How to use Perl in Data Science. Again, this idea is not mine as it was mentioned in perlblogs as a desire to have a new PDL book. Maybe with a help from Perl foundation such a project could encompass even more than PDL and include several other modules suited for data science.

    Another interesting idea that I have encountered was to create Perl/XS graphics backend as there is a need to have graphic library which can create 2D/3D chart easily - see the comments on perlblogs. Unfortunately, I know very little about this but I guess that it might be a very hard task... So these are just a couple of examples but actually the main issue is if it is feasible in general - to have a grant for data science using Perl? What do you think? Do you know someone that could be interested in it? Or do you think that this approach is flawed and have some other suggestions?

Cool Uses for Perl
Announcing Perl-based automation of Notepad++
No replies — Read more | Post response
by pryrt
on Feb 22, 2020 at 14:35

    At long last, I have a version of my Perl module for automating Notepad++ (the Windows-based text editor) that Ive been willing to publish.


    Win32::Mechanize::NotepadPlusPlus - Automate the Windows application Notepad++


    use Win32::Mechanize::NotepadPlusPlus ':main'; my $npp = notepad(); # main application


    Automate the Windows application Notepad++. This is inspired by the Notepad++ plugin PythonScript, but I decided to automate the application from the outside, rather than from inside a Notepad++ plugin. But this module uses similar naming conventions and interface to the PythonScript plugin.


    This is the first public release of the module. In general, it works. As with all first releases, there is room for improvement; I welcome feedback.

    The first known limitation is that none of the hooks for Scintilla or Notepad++ callbacks have been enabled. That may come sometime in the future.

    All the testing and development was done with a US-English installation of Notepad++, and all the file encodings have been ANSI or UTF-8. I know that I need to include better tests for encoding, and any help you can provide with that is appreciated.

    Notepad++ is a Windows application, so that's the intended platform for this module. However, I know Notepad++ can be made to run in Wine and similar environments in Linux, so it may be possible to make this module drive Notepad++ in such an environment. Feedback on this process is welcome.


    To install this module, use your favorite CPAN client.

    For a manual install, type the following:

    perl Makefile.PL make make test make install

    (You may need to use "dmake" or "gmake" instead of "make", depending on your setup.)


    Peter C. Jones

    Please report any bugs or feature requests thru the repository's interface at, or by emailing <bug-Win32-Mechanize-NotepadPlusPlus AT> or thru the web interface at


    Copyright (C) 2019,2020 Peter C. Jones


    This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See for more information.

PerlMonks Discussions
Chatterbox: NEW link to sent messages
No replies — Read more | Post response
by LanX
on Feb 16, 2020 at 07:11

    Private /msg [messages] are sometimes hard to understand if they are a reply to something you wrote a day ago.

    Actually they are still available in the "Delete" folder but only for a limited time (36h ?)

    click here to check

    The chatterbox nodelet used to have various links to the message box in the bottom row

       And 69 more, 90 archived

    It now contains a link to recently sent messages too

       And 69 more, 90 archived, recently sent

    The "recently" was necessary to avoid confusion about older messages missing. You need to archive them explicitly if you want keep them longer.

    Thanks to the gods for accepting my patch. :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    ) The link is a bit long for my taste, probably "just sent" or only "sent" with alt-text would have been better

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2020-02-23 05:40 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (102 votes). Check out past polls.