Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

The Monastery Gates

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

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
12 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.

Perl News
Tau Station Perl MMORPG Kickstarter Launched
on Oct 05, 2020 at 13:21
3 replies by Ovid

    There's a song by Shaggy, "It wasn't me", that is running through my head. If you're familiar with it, it's somehow both catchy and vile. I've had ex partners describe me that way.

    The song is running through my head because I'm not the one who accidentally launched the Tau Station Kickstarter several days early. But it's done.

    And they won't let us restart it.

    So maybe it's not our intended launch window. Maybe we weren't ready. But we're owning this. We're making this happen.

    Please help support the world's first Biblio-RPG. It's a massive, immersive, narrative sci-fi MMO. And it's over 400,000 lines of Perl. Let's show the world what Perl can do.

    Even if you don't want to join in, please share this with everyone!

    Here's the link to the Kickstarter.

    And here's a link to the game. It's free to play and runs in any relatively modern browser, so you won't need to download anything or spend any money. usable again
on Oct 01, 2020 at 05:12
2 replies by hippo
Understanding Devel::Peek output
2 direct replies — Read more / Contribute
by syphilis
on Nov 29, 2020 at 07:32

    On my 64-bit Windows 7 OS, I have:
    1) perl-5.32.0 built using a 32-bit gcc-8.3.0 compiler;
    2) perl-5.32.0 built using a 64-bit gcc-8.3.0 compiler.

    On both of those perls, the ivtype is the 8-byte "long long".

    On the 32-bit build I get:
    C:\>perl -MDevel::Peek -e "Dump 1 << 62;" SV = IV(0x1dc8d64) at 0x1dc8d64 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 4611686018427387904
    Note that the first line contains two occurrences of the same hex value - 0x1dc8d64 in this instance. Every time I run that command on that 32-bit build of perl, the two hex values are always equivalent - though, of course, they're not always 0x1dc8d64.

    When I run the same command on the 64-bit build, I get:
    C:\>perl -MDevel::Peek -le "Dump 1 << 62;" SV = IV(0x33d430) at 0x33d440 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 4611686018427387904
    For this build of perl, it is always the case that the first hex value is less than the second value by 0x10.

    How is this differing behaviour between the 32-bit build and the 64-bit build explained ?

    IIUC, on the 64-bit build, the amount of memory being allocated for the IV is 0x10 (16) bytes more than is necessary ... and I wonder what is responsible for that extravagance.
    Is it perl ? ... or the OS ? ... or the compiler ? ...

Formatting variables
6 direct replies — Read more / Contribute
by Bod
on Nov 29, 2020 at 06:24

    I have been rereading Re^3: Pointers and References and pondering variable names. It is clear from comments that different people have different conventions for how they name and structure their variable names. This is not something I have given much thought to until recently.

    With the exception of constants, in the past I have generally used all lower case with an underscore sometimes between words although omitted if the name is clearly discernable. Over the last year or so I've started capitalising the first letter of each word other than the first which works better I think with more than two words.
    For example $user_number and $userNumber.

    Last evening I was writing some code around CRM access permissions within different business units and ended up with some poor variable names within the Perl generated web form:

    crmr_5 Read access to business unit 5 crmw_3 Write access to business unit 3 crmn_1 Read and write notes access...

    I'm wondering how you do it, why you do it that way and if you think it matter a great deal.

[Win32] Escaping quotes in perl one liner
3 direct replies — Read more / Contribute
by syphilis
on Nov 28, 2020 at 01:48

    I run:
    C:\_32>type open(my $x,">&STDOUT"); C:\_32>perl C:\_32>perl -le "open(my $x,\">&STDOUT\");" >& was unexpected at this time. C:\_32>
    Why does the one-liner throw that error ?
    Having escaped both double quotes I expected the one liner to behave in exactly the same way as the script - ie to simply silently exit.

    I know that replacing the double quotes with singles works around the issue:
    C:\_32>perl -le "open(my $x,'>&STDOUT');" C:\_32>
    But is there a way to retain the use of double quotes and still get the one-liner to DWIM ?

mod_perl on apache works when symlinked to one directory but not to another
3 direct replies — Read more / Contribute
by Cody Fendant
on Nov 27, 2020 at 22:43

    This is kind of an embarrassing one. I'm sure I must be missing something obvious.

    I have a Catalyst based website running in mod_perl.

    There are two versions of the website, let's call them old and new (new was cloned from a remote git repo to the server, could that be causing the problem?)

    • The website works when the directory /var/www is symlinked to old, as in

      ln -s /path/to/old /var/www

    • The website does not work when the directory /var/www is symlinked to new, as in

      ln -s /path/to/new /var/www
      (removing the old link first of course).

    The reason it doesn't work, seen in apache error logs, is that it can't find the custom perl modules in /path/to/new. It says it can't find them in @INC and that @INC contains /var/www and /var/www/whatever/lib/Module/etc which is correct

    When I remove that symlink and re-link /path/to/old it works just fine.

    If I do perl -I/path/to/new -MSome::Module::In::New there's no problem, it finds the module just fine.

    I've checked permissions and made sure they're the same, or even less restrictive on the files in /path/to/new. The relative paths are all correct, as far as I can see my /path/to/old and /path/to/new directories are exactly the same, except that apache/mod_perl can see one and not the other.

    This is on an Amazon EC2 running linux by the way.

2 direct replies — Read more / Contribute
by marcelv
on Nov 26, 2020 at 15:32

    Hi all,

    I currently have quite some scripts running on Perl 5.24 on a Microsoft Windows Server running IIS 10.0. On this server I use a certificate to for HTTPS connections. The scripts are all using the module to do CGI. As I do use Non-Parsed Headers (NPH), all my scripts start with the prefix "nph-" and have the following line to import the CGI module:
    use CGI qw/:standard -nph/;

    Now when a browser requests one of my scripts, these scripts are executed twice. I have made a Wireshark trace and I see the following happening:

    1. The browser does the TLS handshake
    2. The browser does a HTTP2 request to the script
    3. The server responds with HTTP_1_1_REQUIRED
    4. The browser does another request, but now uses HTTP/1.1
    5. The server sends a HTTP/1.1 response with the script output

    This is most evident when Firefox is used, as it does not remember it should use HTTP/1.1 for the request, where Chrome, Edge and Safari do remember.

    Now when I remove the "nph-" prefix from the script name (and do not change the contents), the following happens:

    1. The browser does the TLS handshake
    2. The browser does a HTTP2 request to the script
    3. The server sends the HTTP2 response with the script output

    Now I could change all my script names by removing the "nph-" prefix, but it seems that the scripts do not really do NPH anymore as the server is sending back a HTTP2 response, whereas with the "nph-" prefix the exact headers as generated by my script are received by the browser.

    Now my question: is it possible to HTTP2 via CGI using the CGI module or any other module?


Regexp substitution using variables
7 direct replies — Read more / Contribute
by MikeTaylor
on Nov 25, 2020 at 14:20
    I have a string $value that I want to transform by regexp substitution. But the pattern, replacement and flags are known only at run-time. They are specified by $pattern, $replacement and $flags. So I want to do something like
    $value =~ s/$pattern/$replacement/$flags;
    but of course that doesn't work as intended. Or perhaps something like this, if I could only find the right class name:
    my $re = new Regexp($pattern); my $value = $re->substitute($value, replacement, $flags);
    There has to be way to do this ... right?
script hanging at thread start
6 direct replies — Read more / Contribute
by armcinto
on Nov 24, 2020 at 14:53

    Hi Monks,
    I'm stuck and need some direction. I have a new script that is frequently hanging and needs to be killed. The script reads in a file with a list of hostnames (4-5) and creates a thread for each hostname. I can see the print statement that each thread is created, but I don't see the first print statement in the runMain subroutine. Most of threads complete the entire script, but 1-2 will appear to never start. Not sure what else to try at this point to get more information. This is Strawberry Perl (64-bit) environment.

    sub runMain { print "Starting runMain on $_[0]\n"; if ($_[0] =~ /(\w.+\w\d+.+net),(\w+)/) { $Server = $1; $Type = $2; print "Connecting to $Server\n"; } } open (LIST, "list.txt"); for my $Serv (<LIST>) { print "Created thread for $Serv\n"; push @Threads, threads->new(sub {runMain($Serv)}); }

Can't locate conf.cgi in @INC
1 direct reply — Read more / Contribute
by CarlosN
on Nov 23, 2020 at 17:20
    Hello, I am installing a Perl autoresponder script in my cgi-bin with a script called install.cgi and I get this error:
    Software error: Can't locate conf.cgi in @INC (@INC contains: lib /usr/local/lib64/per +l5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/per +l5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at install.cgi line + 14. For help, please send mail to the webmaster...
    My issue is that there actually is a directory called "lib" as stated above in the error message: " @INC contains: lib " and the necessary perl modules are located there. I even tried using:
    use FindBin; use lib "$FindBin::RealBin/..";
    and what that did is print the whole path to the parent dir within the error message, and install.cgi just won't execute. Any suggestions? Thanks, Carlos
A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console
2 direct replies — Read more / Contribute
by cxw
on Nov 30, 2020 at 10:32

    (This is my first meditation. I am posting in hopes it will help someone down the line! I can't find another node about this, but that doesn't mean there isn't one :) .)

    I needed to run a program and then wait for the user to hit Enter. I tried this:

    $ perl -e 'system(@ARGV); readline' echo foo foo Can't open echo: No such file or directory at -e line 1. Can't open foo: No such file or directory at -e line 1.
    Not what I expected!

A short whishlist of Perl5 improvements leaping to Perl7
9 direct replies — Read more / Contribute
by rsFalse
on Nov 24, 2020 at 03:07
    As Perl7 is announced (Announcing Perl 7), and it will be "v5.32 but with different, saner, more modern defaults".
    I'll suggest a list of improvements:
    • Make keyword "my" optional. It MUST be unnecessary to declare all lexical variables as lexical if 'use strict' is ON by default. If 'use strict' is ON then so called 'automine'(Re^4: Opinion: where Perl5 wasn't attractive for me) should be ON by default also. I mean 'my' becomes redundant, isn't it?
Cool Uses for Perl
Link push/digital signage server+client
No replies — Read more | Post response
by Corion
on Nov 27, 2020 at 09:32

    Sometimes I want to display the same HTML page on multiple devices. Think photo album or something else.

    Sometimes I want to "push" an URL, and then pick it up from a single device.

    This server does both:

    The /set URL is where you can enter the URL, and where you also can find a bookmarklet to send whatever current page to the server.

    The /iframe URL will be used by any client for the digital signage.

    The / URL will directly redirect to the target URL. I use that when I'm watching a stream on one device but want to continue to watch it on another device.

    The repository is at

    use Mojolicious::Lite '-signatures'; use Mojo::JSON 'encode_json'; our $VERSION = '0.01'; our $url; get '/' => sub($c) { return $c->redirect_to($url); }; get '/set' => sub( $c ) { if( my $url = $c->param('url')) { $url = $c->param('url'); warn "Set URL to <$url>"; notify_clients({ src => $url }); }; $c->stash( url => $url ); $c->render( template => 'set'); }; post '/set' => sub($c) { $url = $c->param('url'); $c->stash( url => $url ); warn "Set URL to <$url>"; notify_clients({ src => $url }); }; get '/iframe' => sub( $c ) { $c->stash( url => $url ); $c->render( template => 'iframe'); }; my %clients; my $id = 0; websocket '/cnc' => sub( $c ) { $clients{ $id++ } = $c; $c->on( message => sub( $c, $msg ) { # we don't handle clients talking to us }); }; sub notify_clients( $msg ) { my $str = encode_json( $msg ); for my $id (keys %clients) { eval { $clients{ $id }->send($str); }; if( $@ ) { delete $clients{ $id }; }; }; } app->start; __DATA__ @@ set.html.ep <html> <body> <form method="POST" url="/set"> <label for="url">Enter URL to share:</label> <input id="url" type="text" name="url" placeholder=" +" value="<%= $url %>" /> <input type="submit"/> </form> <a href="javascript:void(new Image().src='<%= $c->url_for('/set')->to_ +abs %>?url='+encodeURIComponent(document.location))">Bookmarklet for +setting a link to the current page</a> </body> </html> @@ iframe.html.ep <!DOCTYPE html> <html> <head> <!-- just in case the ws breaks down --> <meta http-equiv="refresh" content="300; URL=<%= $c->url_for('/iframe' +) %>"> <title>URL receiver</title> <script> let ws_uri = "<%= $c->url_for('/cnc')->to_abs() =~ s!^http!ws!r %>"; window.uplink = new WebSocket(ws_uri); window.uplink.onmessage = (event) => { let target = document.getElementById('iframe'); console.log(; let msg = JSON.parse(; try { target.src = msg.src; } catch(e) { console.log(e); }; }; </script> </head> <body style="margin:0px; padding:0px;"> <iframe id="iframe" style="width: 100%; height: 100%; position: absolu +te; border: none;" frameborder="0" allowfullscreen allow='autoplay' s +rc="<%= $url %>"/> </body> </html>
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 browsing the Monastery: (7)
As of 2020-11-30 17:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found