Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
2 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
Pumpking resignation
on Apr 13, 2021 at 10:39
7 replies by davies

    This was discussed in the chatterbox yesterday. Analysis, with links for those who want to be even more depressed, is at I wish I had the technical skills to volunteer.


    John Davies

    Update for thost of you suggesting tech skills aren't needed. I have never written a line of C. I have no idea what a makefile does. Spreadsheets running VBA or 123 macros are my comfort zone. And yes, I'm still comfortable with the /X versions of 123 macros.

The "A" in awk has gotten a special award
on Mar 31, 2021 at 20:04
1 reply by perlfan
Disable Plack::Middleware::AccessLog
2 direct replies — Read more / Contribute
by 1nickt
on Apr 17, 2021 at 20:09

    Learned friends,

    The doc for Plack::Middleware::AccessLog states This middleware is enabled by default when you run plackup as a default development environment.

    I am wanting to run another middleware for logging and thus wish to disable the default. Can anyone tell how?


    The way forward always starts with a minimal test.
Making distribution on Strawberry Perl for CPAN
2 direct replies — Read more / Contribute
by Bod
on Apr 16, 2021 at 19:09

    I've uploaded Business::Stripe::WebCheckout to CPAN as a developer release. Release 1 failed when Stripe couldn't be contacted. Release 2 has cured this problem and, so far, all the CPAN Testers reports have passed 😊

    However, Windows doesn't have gzip. So in Makefile.PL I have this line to use IO::Compress::Gzip which is included with Strawberry Perl:

    dist => { COMPRESS => q{perl -MIO::Compress::Gzip=gzip,:constants -e" +my $$in = $$ARGV[0]; gzip($$in => qq($$in.gz), q(Level) => Z_BEST_COM +PRESSION, q(BinModeIn) => 1) or die q(gzip failed); unlink $$in;"}, S +UFFIX => 'gz', },
    This is included in the tarball that was uploaded.

    Does this need changing in the release?
    My best guess is that it is OK as it is only used when building the distribution, not when installing it but I wanted to check this is correct.

Obtaining OAuth2 Access Token
1 direct reply — Read more / Contribute
by Bod
on Apr 16, 2021 at 10:07

    I am trying to connect to LinkedIn using LWP::Authen::OAuth2. Authorisation goes fine but when I come to exchange the authorisation token for an access token, I get this error:

    Endpoint: JSON: { "serviceErrorCode":65604, "message":"Empty oauth2 access token", "status":401 }
    That doesn't seem to make alot of sense to me as I would expect the OAuth2 Access Token to be empty in a request to get it!

    This is the bare bones of what I am doing...

    my $linkedin = LWP::Authen::OAuth2->new( client_id => 'xxxxxxx', client_secret => 'xxxxxxx', authorization_endpoint => ' +uthorization', token_endpoint => ' +en', redirect_uri => "https://$ENV{'HTTP_HOST'}/cgi-bin/pos", scope => 'w_member_social', save_tokens => \&save_linkedin_token, ); ######################### # LinkedIn button clicked sub linkedin { my $auth_url = $linkedin->authorization_url; print "Location: $auth_url\n\n"; exit 0; }
    The code above behaves as expected by going off to LinkedIn, authorising the app and calling the callback URL
    The callback URL does this:
    sub authorize_linkedin { my $token = $linkedin->request_tokens( code => $data{'code'}, ); print "Content-type: text-plain\n\n"; print "ERROR: $data{'error'}\n\nMessage: $data{'error_description' +}\n\n"; print "TOKEN: $token\n"; print $data{'code'}; exit 0; }
    The error (above) is generated at the request_tokens call. $data{'code'} contains the code passed as a query parameter to the callback URL.

    I feel I must be missing something obvious here...

(Windows) verbatim command line arguments inside Perl script
4 direct replies — Read more / Contribute
by LanX
on Apr 16, 2021 at 08:37

    I need to write a Perl script which is generating a .bat-file while passing it's command line arguments 1-to-1

    Is there any way to access the "raw" command-line in order to catch quoting and escaping?

    To highlight the problem:

    D:\>perl -E"say qq(@ARGV)" "1 2" "3" 4 1 2 3 4

    As you can see are all quotes and escapes lost while calling Perl (for good reasons)

    But my script has to generate another .bat which does

    ... some_cmd "1 2" "3" 4 ...

    Typical edge-case justifying this problem are win-paths with whitespace, but cmd.exe has also some arcane escaping rules.

    I already have a workaround:

    I discovered that .bat has %* to hold the verbatim command line arguments, and came up with a workaround of a .bat calling my perl-script

    D:\tmp\exp>type cmd_wrapper.bat @echo off echo %* |perl -wE"chomp(my $args = <STDIN>);say qq(some_cmd $args)" D:\tmp\exp>cmd_wrapper.bat "1 2" "3" 4 some_cmd "1 2" "3" 4 D:\tmp\exp>

    Question: any better solution?

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

    PS: I don't think this question is overly Win specific, when creating a bash script on Linux I'd face the same problem.

DateTime throwing an error
1 direct reply — Read more / Contribute
by nachtmsk
on Apr 15, 2021 at 20:16


    I have a script in cron that I haven't changed in months. I use the DateTime module in the script. This afternoon, the script stopping running properly. I ran the script manually and received the error below.

    Unrecognized character \x0E; marked by <-- HERE after warnings;<-- HE +RE near column 14 at /usr/local/share/perl/5.28.1/Role/Tiny/ l +ine 4. Compilation failed in require at /usr/local/share/perl/5.28.1/Specio/C line 10. BEGIN failed--compilation aborted at /usr/local/share/perl/5.28.1/Spec +io/ line 10. Compilation failed in require at /usr/local/share/perl/5.28.1/Specio/D line 11. BEGIN failed--compilation aborted at /usr/local/share/perl/5.28.1/Spec +io/ line 11. Compilation failed in require at /usr/local/lib/arm-linux-gnueabihf/pe +rl/5.28.1/DateTime/ line 12. BEGIN failed--compilation aborted at /usr/local/lib/arm-linux-gnueabih +f/perl/5.28.1/DateTime/ line 12. Compilation failed in require at /usr/local/lib/arm-linux-gnueabihf/pe +rl/5.28.1/DateTime/ line 12. BEGIN failed--compilation aborted at /usr/local/lib/arm-linux-gnueabih +f/perl/5.28.1/DateTime/ line 12. Compilation failed in require at /usr/local/lib/arm-linux-gnueabihf/pe +rl/5.28.1/ line 14. BEGIN failed--compilation aborted at /usr/local/lib/arm-linux-gnueabih +f/perl/5.28.1/ line 14. Compilation failed in require at line 8.

    I thought possibly something because corrupt so I tried to reinstall DateTime using cpan.
    When I do that I get a lot of the same error as above.

    Any suggestions on how to proceed?


Mojolicious-Hypnotoad-Nginx - rendering images
4 direct replies — Read more / Contribute
by pdkakoba
on Apr 15, 2021 at 09:24

    Kindly seeking assistance in rendering images (any static file from /public) in a default Mojolicious-Hypnotoad-Nginx setup. Following the standard guides, this setup successfully renders the default welcome page. However adding one exception: a .png image to this page, it is not rendered, even the favicon.ico doesn't appear.

    There is mention of "hooks" needed to correct for the workings of a Reverse Proxy, but after a long search one doesn't find a clear full example -- particularly for Nginx.

    The welcome.html.ep has this simple addition: tree. It appears alone as an image when one enters this url:

SerialPort issues under Windows 10
3 direct replies — Read more / Contribute
by clinicalAD
on Apr 15, 2021 at 06:46
    Hello, Am trying to use Win32::SerialPort on a portable strawberry perl implementation, version 5-32-1. (32 bit). Using it to try and set up a datalogger on a Win10 machine, for an instrument that reports through a RS232 output. Also have a general test bed which is two windows PCs connected by a serial cable, and one sending messages (from Powershell) to the other - which testing has shown acts in the same way as the end use. Have come across a variety of scripts online. For some reason though, I can't get any Perl script to output the RS232 input on its own. However, if I open and close the port in powershell, suddenly the exact same Perl script DOES work! The perl script continues to work as expected until the PC is rebooted. So I'm wondering if there's a key parameter needing to be set, which is sorted by Powershell but not by Perl? Couldn't see anything obvious in the SerialPort documentation. An example script that only works when powershell has "activated" the port is:
    use Win32::SerialPort; # Use instead for Windows my $port=Win32::SerialPort->new("COM1") || die "couldn't open COM1"; $port->baudrate(9600); # Configure this to match your device $port->databits(8); $port->parity("none"); $port->stopbits(1); #$port->handshake("none"); $port->user_msg(ON); print "Port COM1 successfully opened\n"; $count = 0; my $chars=0; my $buffer=""; print "1\n"; do { print "2\n"; my ($count,$saw)=$port->read(255); # will read _up to_ 255 char +s print "3\n"; if ($count > 0) { $chars+=$count; $buffer.=$saw; print $saw; } print "4\n"; $port->lookclear; print "5\n"; } while 1; $port->close;
    This code stops after printing "2" if I've not opened/closed the port in Powershell yet - it's the reading of RS232 input where the script seems to get blocked quite consistently across different scripts. Powershell code to open and close is:
    $port = new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one $ $port.close()
    Powershell to send RS232 on test bed is: $port.WriteLine("test") Unfortunately access permissions do not let me run a powershell script, and I'd rather not have the end user have to manually type in powershell code each time the PC is turned on... Many thanks for any advice provided.
Crypt-Random-Source: 0.14 fails to install
2 direct replies — Read more / Contribute
by chandantul
on Apr 14, 2021 at 09:02

    Hello All, I am getting the following error Crypt-Random-Source: 0.14 fails to install while installing OIDC::Lite. I am in Windows 10 platform

    Please check below errors

    t/sugar.t .............. 1/? Undef did not pass type constraint "Class +Name" (in $self->{"weak_source"}) at (eval 121) line 17 "ClassName" is a subtype of "Str" "Str" is a subtype of "Value" "Value" is a subtype of "Defined" Undef did not pass type constraint "Defined" (in $self->{"weak_sou +rce"}) "Defined" is defined as: (defined($_)) # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 255 just after 3. t/sugar.t .............. Dubious, test returned 255 (wstat 65280, 0xff +00) All 3 subtests passed Test Summary Report ------------------- t/factory.t (Wstat: 65280 Tests: 1 Failed: 0) Non-zero exit status: 255 Parse errors: No plan found in TAP output t/sugar.t (Wstat: 65280 Tests: 3 Failed: 0) Non-zero exit status: 255 Parse errors: No plan found in TAP output Files=7, Tests=17, 4 wallclock secs ( 0.11 usr + 0.09 sys = 0.20 CP +U) Result: FAIL Lockfile removed. ETHER/Crypt-Random-Source-0.14.tar.gz C:\Strawberry\perl\bin\perl.exe ./Build test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports ETHER/Crypt-Random-Source-0.14.tar.gz Stopping: 'install' failed for 'Crypt::Random::Source'. Failed during this command: ETHER/Crypt-Random-Source-0.14.tar.gz : make_test NO

    Can you please help to fix?

Breaking symmetry with a regex
6 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 13, 2021 at 18:50

    I have a string that has the form 'a:b:' where 'a' and 'b' are both numbers. How do I drop the second colon, or convert it to // ?

Should I use v5.10 because of named groups?
5 direct replies — Read more / Contribute
by hrcerq
on Apr 13, 2021 at 18:11

    Hello again.

    I've got a script that uses named capture groups to parse file records. The record format is always the same (four fields wide, colon separated), just like a passwd file (except for the number of fields).

    For example:


    You get the idea. At first I used to split it, but later I came to the conclusion that using a regex with named groups could provide a more understandable code. The (simplified) example below might help you get the picture.

    if (/^(?<type>[01]):(?<valid>[01]):(?<name>[^:]+):(?<comment>[^:]+)$/) + { print "Key name: ", $+{name}, "\n"; print "Key Comment: ", $+{comment}, "\n"; print "Not valid\n" unless $+{valid} || !$+{type}; } else { print "Malformed input: $_\n"; }

    Now, I've noticed (according to perlretut) that named capture groups were introduced in Perl 5.10. I don't expect the script to run in older versions, but would it be wise to use v5.10 pragma?

    Would it have any unwanted side effects? I'm not using any of the features of the bundle, just wanted to state that version 5.10 is required. Is that a good idea?

Useless use of string in return statement
7 direct replies — Read more / Contribute
by Bod
on Apr 12, 2021 at 19:06

    Is there something strange about the way return treats conditions?

    I have this and it doesn't work as expected...

    sub get_ids { my ($self, %attrs) = @_; # Do stuff... my %result; # $result{'message'} = ''; if ($self->{'error'}) { $result{'status'} = 'error'; $result{'message'} = $self->{'error'}; } else { $result{'status'} = 'success'; $result{'api-key'} = $self->{'api-public'}; $result{'session'} = $intent_id; } return encode_json(\%result) if lc($attrs{'format'}) eq 'json'; return $result{'message'} or "$result{'api-key'}:$result{'session' +}"; # <- line 229 return "SOMETHING"; }
    If it is called as get_ids( 'format' => 'json' ); it works fine but asking it to return a text string returns undef and warns Useless use of string in void context at line 229. The way I think it should work is that if $result{'message'} evaluates as true, that will get returned but if it evaluates as false then "$result{'api-key'}:$result{'session'}" wil be returned instead.

    Can you explain why this is not behaving as expected?

    As an aside, in searching for an answer I found this post -> Useless use of string in void context
    There it is suggested that Perl reports the wrong line number for this warning so it is quite possible that I'm actually looking in the wrong place!

LinkedIn module
1 direct reply — Read more / Contribute
by Bod
on Apr 12, 2021 at 08:07

    Searching CPAN I was rather surprised that the only general modules for connecting to LinkedIn seem to be WWW::LinkedIn and Net::Linkedin::OAuth2 - both of these date from before Microsoft acquired LinkedIn 5 years ago...unbelievable that it is that long ago!

    Since the 5th April, Hootsuite have reduced the number of scheduled posts permitted on free accounts down to just 5 and we don't use the other features to warrant the paid price tag. We already have an automated Twitter scheduler and I want to add LinkedIn to it so just need something to authenticate, read the timestamp of the latest post and be able to create a post containing media.

    Before I write something to do this, are there any modules available or should I try out the modules above despite their age?

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 pondering the Monastery: (4)
As of 2021-04-18 09:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found