Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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.

Quests
poll ideas quest 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
0 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
Coding in Perl? What support do you need?
on Jan 06, 2021 at 05:15
7 replies by marto

    Coding in Perl? What support do you need? over at the Perl foundation website has a linked survey:

    "But think about this. If we switched Perl off today, there would be a problem. A huge problem! We know that Perl is the glue that holds a lot of the IT world together. The Perl Foundation wants to support the community to make sure that the IT world doesn’t fall apart and supporting people learning Perl is a big element of that.

    We have developed a survey that needs just a few minutes of your time, to tell us what you would like, or need, to support your move into, or progress within, the Perl language."

Phishing Attack on CPAN Authors
on Jan 04, 2021 at 18:08
1 reply by hippo

    As announced by TPF. Take care, everyone.


    🦛

Supplications
let Makefile.PL to do the Readme file for me -- new target?
5 direct replies — Read more / Contribute
by Discipulus
on Jan 19, 2021 at 11:36
    Hello folks!

    Despite many years programming in Perl I'm at my second real module. I'm used to module-starter that uses ExtUtils::MakeMaker as default builder.

    My laziness got suddenly annoyed to maintain a Readme file manually: I brutally copy my pod output to this file, but I must remember to do it anytime I modify the doc.

    I supposed to automate this and I asked here and there. I was pointed to Overriding-MakeMaker-Methods where is stated:

    > Here is a simple example of how to add a new target to the generated Makefile:

    The only working (for my purpose) modification to my Makefile.PL is the following

    sub MY::postamble { return <<'MAKE_README'; postamble :: $(PERLRUN) -MPod::Text \ -e "Pod::Text->new (sentence => 1, width => 78)->parse_from_file( +qw( $(TO_INST_PM) Readme) );" MAKE_README }

    Which modify the end of resulting Makefile generated by perl Makefile.PL from:

    # --- MakeMaker postamble section: # End.

    to this:

    # --- MakeMaker postamble section: postamble :: $(PERLRUN) -MPod::Text \ -e "Pod::Text->new (sentence => 1, width => 78)->parse_from_file( +qw( $(TO_INST_PM) Readme) );" # End.

    Then I can succesfully run dmake postamble (yes strawberry perl has dmake) to have my Readme updated.

    Questions

    MY::postamble is a fixed name? Both the class MY and the postamble name are fixed? I tried different names and it always complains: dmake:  Error: -- Don't know how to make `customname' Cannot the creation of the Readme integrated inside make dist or other similar steps?

    Or should I treat Makefile.PL as a normal perl program putting my custom do_readme sub call before WriteMakefile one?

    It's only me or the docs are sybilline and stingy of words?

    PS I have chatted a bit on #perl channel about this and the discussion diverged on authoring tools (where ExtUtils::MakeMaker is not an authoring tool). mbtiny was suggested and also Distar with some interesting read: A-BRIEF-HISTORY-OF-AUTHORING and a COMPARISON

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Strange behaviour when regex variable is modified during match?
4 direct replies — Read more / Contribute
by rsFalse
on Jan 17, 2021 at 11:51
    Hello.

    Today I found a strange behaviour in my sandbox program after I tried to soft-code a variable. Here is my code:
    #!/usr/bin/perl use warnings; use strict; $\ = $/; my $A = "1112" # . '' ; @_ = ( 'a' .. 'i' ); $A =~ /1+ (??{ print "[$&]"; $_ .= shift @_; s!\B!shift@_!e; print "\$_:[$_]"; }) $ /x;
Text::Summarizer fails on Windows 10
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 16, 2021 at 13:21

    Hello

    I am trying to install on Windows 10, Strawberryperl v5.28.1, the module Text::Summarizer. I get the following - for my knowledge - strange error. Do you know what can I do to solve this issue?

    cpanm Text::Summarizer --> Working on Text::Summarizer Fetching http://www.cpan.org/authors/id/F/FA/FAELIN/Text-Summarizer-2. +01.tar.gz ... OK Could not create directory 'C:\Users\TE\.cpanm\work\1610820965.16324\T +ext-Summarizer-2.01\Corpus\written\newspaper:newswire' for 'Text-Summ +arizer-2.01/Corpus/written/newspaper:newswire': mkdir C:\Users\TE\.cp +anm\work\1610820965.16324\Text-Summarizer-2.01\Corpus\written\newspap +er:.: Invalid argument; Die Syntax f³r den Dateinamen, Verzeichnisnam +en oder die Datentrõgerbezeichnung ist falsch at C:/Strawberry/perl/l +ib/Archive/Tar.pm line 819. at C:\Strawberry\perl\bin\cpanm.bat line 132. Could not extract 'Text-Summarizer-2.01/Corpus/written/newspaper:newsw +ire' at C:\Strawberry\perl\bin\cpanm.bat line 132. ==> Found dependencies: Module::Build Found Module::Build 0.4231 which doesn't satisfy 2.01. ! Installing the dependencies failed: Installed version (0.4224) of Mo +dule::Build is not in range '2.01' ! Bailing out the installation for Text-Summarizer-2.01.
mysteries of regex substring matching
4 direct replies — Read more / Contribute
by smile4me
on Jan 15, 2021 at 16:42

    We all know that "In list context, a regex match returns a list of captured substrings." And, we also know "Numeric quantifiers express the number of times an atom may match. {n} means that a match must occur exactly n times." So can the numeric quantifier work with the captured substrings?

    perl -E '$s = q[AAD34017837201D98AAED18778DEF993]; say length($s), " ", $s; @m = $s =~ /(....)(....)(....)(....)(.+)/; say "", join("-",@m);' # 32 AAD34017837201D98AAED18778DEF993 # AAD3-4017-8372-01D9-8AAED18778DEF993

    In contrast, the following regex uses a numeric quantifier but does not work as above:

    perl -E '$s = q[AAD34017837201D98AAED18778DEF993]; say length($s), " ", $s; @m = $s =~ /(....){4}(.+)/; say "", join("-",@m);' # 32 AAD34017837201D98AAED18778DEF993 # 01D9-8AAED18778DEF993

    So, is there a way to use capture groups to match multiple times like separate groups does in the first example?

How to display Tk window without waiting for user input
5 direct replies — Read more / Contribute
by Special_K
on Jan 15, 2021 at 15:56

    I am working on a script whose logic is essentially as follows:

    #!/usr/bin/perl -w use strict; use Tk; my $status = 0; my $prev_status = 0; my $mw = MainWindow->new(); $mw->withdraw(); while (1) { my $status = check_for_status(); if ($status != $prev_status) { # need to notify user but don't wait for click $mw->messageBox( -title => 'status changed', -message => 'status changed', -type => 'OK', -icon => 'info', ); } $prev_status = $status; }

    I would like the window to display and also have the program keep executing, but currently the program waits for the user to click "OK". The windows are only intended to notify the user that the status variable has changed and no action is taken based on clicking OK to close the windows. I was not able to find a Tk window type that does not have some sort of dialog button that causes execution to wait for the user to click them.

    I also considered somehow using fork() to spawn off each dialog window as a separate process, but exec() expects a system call. Is there an equivalent to exec() that accepts a block of perl code that I can use to spawn off each dialog window and have execution continue within the main loop? Status changes are relatively infrequent so I don't expect the computer to be swamped with open dialog boxes.

SSL certificate store for a Perlbrew install
2 direct replies — Read more / Contribute
by chrestomanci
on Jan 14, 2021 at 11:48

    Greetings wise brothers, I seek your advice on secret communication an how we can be sure we know who we are talking to.

    Specifically, I am trying to get LWP::UserAgent running inside a locally compiled perlbrew install, to accept a corporate root cert.

    At my company, IT have created a private SSL certificate keypair, and used it to sign the ssl certs on numerous internal servers. They also publish the public half of the SSL cert which (on ubuntu) I have installed in /etc/ssl/certs/ where it is accepted by system perl, firefox, wget etc.

    For some reason the corporate public certificate is not accepted by a perlbrew install of perl 5.10 that I have compiled localy. Do I need to install the corporate root cert somewhere else for perlbrew to accept it?

    Code to reproduce

    use strict; use warnings; use XML::Simple; use LWP::UserAgent; use Data::Dumper; my $url = "https://--- REDACTED ----"; my $parser = new XML::Simple; my $ua = new LWP::UserAgent; # $ua->ssl_opts( verify_hostname => 0 ,SSL_verify_mode => 0x00); my $req = new HTTP::Request('GET', $url); my $resp = $ua->request($req); # print "Result from fetching $url : " . Dumper($resp); if( $resp->is_success() ){ # print "Result content: ". $resp->content; eval{ my $parsed_xml = $parser->XMLin($resp->content, ForceArray => +['publishedfile']); }; if( $@ ){ print "Error parsing XML: $@"; } else { print "File downloaded and XML parsed OK" } } else { die "Error fetching $url : ".$resp->message; }

    This code works fine using Ubuntu's system perl on all the versions of Ubuntu I could find. It also works if I uncomment the $ua->ssl_opts( verify_hostname => 0 ,SSL_verify_mode => 0x00); line, But it fails on line 35 with  Can't connect to REDACTED:443 (certificate verify failed) at scripts/dev/test_ssl_download.pl line 35. if I use perlbrew perl.

    Any ideas?

    NB: I asked this question in chatterbox about an hour ago, but did not get a reply, so I am re-posting as a perl question.

Question regarding Time::Piece and timezones
4 direct replies — Read more / Contribute
by atcroft
on Jan 14, 2021 at 01:02

    The documentation for Time::Piece in 5.30.x states the following:

    Date Parsing
    Time::Piece has a built-in strptime() function (from FreeBSD), allowing you incredibly flexible date parsing routines. For example:
    my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943", "%A %drd %b, %Y"); print $t->strftime("%a, %d %b %Y");
    Outputs:
    Wed, 03 Nov 1943
    (see, it's even smart enough to fix my obvious date bug) For more information see "man strptime", which should be on all unix systems. Alternatively look here: http://www.unix.com/man-page/FreeBSD/3/strftime/

    The link includes the following conversion specifications:

    %a is replaced by national representation of the abbreviated weekday name.
    %d is replaced by the day of the month as a decimal number (01-31).
    %b is replaced by national representation of the abbreviated month name.
    %Y is replaced by the year with century as a decimal number.
    %T is equivalent to ``%H:%M:%S''.
    %H is replaced by the hour (24-hour clock) as a decimal number (00-23).
    %M is replaced by the minute as a decimal number (00-59).
    %S is replaced by the second as a decimal number (00-60).
    %Z is replaced by the time zone name.
    %z is replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).

    The page for strptime on the same site says, "The strptime() function parses the string in the buffer buf according to the string pointed to by format, and fills in the elements of the structure pointed to by timeptr. The resulting values will be relative to the local time zone. Thus, it can be considered the reverse operation of strftime(3)."

    I created the following test code as tp_test.pl:

    #!/usr/bin/perl # vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: use strict; use warnings; use Carp; use Time::Piece; $SIG{__WARN__} = sub { Carp::cluck @_; }; $SIG{__DIE__} = sub { Carp::confess @_; }; $| = 1; my $t = localtime; my $pattern = "%a, %d %b %Y %T %Z"; my $str = $t->strftime( $pattern ); print "Time is:\n", $str, "\n"; # Format: Wed, 13 Jan 2021 17:22:23 CST my $u = Time::Piece->strptime( $str, $pattern, ); print "Time is:\n", $u->strftime( $pattern ), "\n";

    I tested the code on the following three (3) platforms:

    • 5.30.1 under MSWin/x86_64 (Strawberry/BerryBrew)
    • 5.30.3 under MSWin/x86_64 (Cygwin64)
    • 5.30.3 under Linux/x86_64
    When I execute the script above, I get the following on all three platforms (differing only by the path to Piece.pm):
    $ perl ./tp_test.pl Time is: Wed, 13 Jan 2021 22:21:49 CST Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 597. at ./tp_test.pl line 11. main::__ANON__("Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 597.\x{a}") called at /usr/lib64/perl5/Time/Piece.pm line 597 Time::Piece::strptime("Time::Piece", "Wed, 13 Jan 2021 22:21:49 CST", "%a, %d %b %Y %T %Z") called at ./tp_test.pl line 23 $

    Expected output:

    $ perl ./tp_test.pl Time is: Wed, 13 Jan 2021 22:21:49 CST Time is: Wed, 13 Jan 2021 22:21:49 CST $

    The behavior also appears to occur if I change my $t = localtime; to my $t = gmtime; as well, where the timezone is then 'UTC'. If it were only occurring under Cygwin and Strawberry, my first guess would be MSWin-related, but since I am seeing it on a Linux system as well, I'm not sure where to look for the cause of the issue.

    Thoughts?

Cool Uses for Perl
A dice roller system with Marpa::R2
1 direct reply — Read more / Contribute
by Discipulus
on Jan 16, 2021 at 09:49
    Hello folks!

    I recently asked for your wisdom in First steps with Marpa::R2 and BNF and I got nice answers. I'm playing with dice in these days as you can see in the post is rand random enough to simulate dice rolls?. The module I finally crafted as toy project is Games::Dice::Roller (with its gitlab repository).

    But I had a sudden desire to reimplement the whole in Marpa::R2 and evolvig duelafn's example and following precious GrandFather's suggestions I ended with the following working code.

    I left in it a lot of debug messages in case someone comes here to look for Marpa::R2 examples.

    It actually mimicry the beahaviour of my Games::Dice::Roller for input received (it still does not accept multistring arguments like 3d6 4d4+1 12 kh as the module does) and it outputs in the same way 3 elements: the result, a descriptive string and the internal datastructure.

    The following code is different from Games::Dice::Roller because it has less constraints in received inputs: for example it accepts something like 6d4r1kh3+3 and computes also a correct result, but messing the description. My mudule would reject an input like this.

    Possible inputs given as argument of the program:

    3d6 # simplest one 3d6+3 # with a result modifier 3d8r1 # reroll and discard any 1 3d8rlt3 # reroll and discard any lesser than 3 3d8rgt6 # reroll and discard any greater than 6 3d8rgt6+2 # reroll and discard any greater than 6 and add +2 to the f +inal result 4d6x1 # explode (a new roll is done) each 1 rolled 4d6xlt3 # explode lesser than 3 4d6xgt4 # explode greater than 4 4d12kh3 # keep highest 3 rolls 4d12kl3 # keep lowest 3 rolls 4d12dh3 # drop highest 3 rolls 4d12dl3 # drop lowest 3 rolls 4d20kh3+7 # keep hishets 3 rolls then add 7

    Alea iacta est!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2021-01-20 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?