Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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


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?

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/ 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");
    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:

    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

    #!/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
    $ perl ./ Time is: Wed, 13 Jan 2021 22:21:49 CST Error parsing time at /usr/lib64/perl5/Time/ line 597. at ./ line 11. main::__ANON__("Error parsing time at /usr/lib64/perl5/Time/ line 597.\x{a}") called at /usr/lib64/perl5/Time/ line 597 Time::Piece::strptime("Time::Piece", "Wed, 13 Jan 2021 22:21:49 CST", "%a, %d %b %Y %T %Z") called at ./ line 23 $

    Expected output:

    $ perl ./ 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.


Detect whether a writeable filehandle has closed?
10 direct replies — Read more / Contribute
by jdporter
on Jan 13, 2021 at 12:26

    In my perl program I open a subprocess for writing via a pipe. It appears that this child process can decide to exit at times I don't expect. Is it possible to detect that the filehandle to the pipe is no longer usable? As it is, I now get SIGPIPE occasionally, but it seems to happen later, after I've possibly already written (tried to write) additional lines to the pipe. I want something synchronous.

    I've seen Scalar::Util's openhandle function. Does it work on pipe handles, opened for writing?


    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
First steps with Marpa::R2 and BNF
5 direct replies — Read more / Contribute
by Discipulus
on Jan 13, 2021 at 08:35
    Hello nuns and monks!

    I've get off the rust over my hands with a toy project recently uploaded to CPAN. It is a dice roller system.

    After ~100 lines of coding, in the above module I had a sudden desire to use Marpa::R2 to accomplish the task of parsing dice expressions. But I terminate my module without any grammar and it accept dice expressions like:

    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

    ..and so on. See the synopsis of my module for more examples.

    Now I want to parse these expressions with Marpa::R2 and I produced cool code I'm proud of you can review at the end of the post.

    Marpa and BNF in general has a lot of documentation and well.. I did not read it all :) It is damn complicated and the enormous amount of documentation produced by Marpa::R2 author is invaluable but also sparse and not precisely destinated to beginners. Or I'm dumb.

    Anyway I have some questions and I'd like simple answers.

    1 - Marpa uses regexes but..

    RHS (Right Hand Symbol) are often like: digits ~ [\d]+ but it seems only character classes can be used. I tried with:  something ~ [(?:this|or|that)]+ but it seems is not the correct usage.

    What can be put at the end of a definition chain?

    2 - Optional terms

    In the below example Dice_with_modifier_x rule works but in the Dice_with_modifier_r I wanted to introduce optional terms: it must accept all these expressions:  3d6r1 3d6rgt4 3d6rlt3 so the r will be always present but followed by an optional gt or lt (greater than and lesser than).

    When I pass 3d8r1 and 3d8rgt1 I get different sized lists ( as shown by dd by Data::Dump ):

    # 3d8r1 modifier_r received: ({}, { die_type => "1d8", rolls => [8, 1, 7] }, " +r", 1) # 3d8rgt1 modifier_r received: ({}, { die_type => "1d8", rolls => [4, 8, 1] }, " +r", "gt", 1)

    Should I work on the size of the list? In my head I'd like something Optional_Modifier_Comparison and if it is not present assume eq as default.

    How must I treat optional eventually empty terms?

    I have put Die_Modifier_Comp ~ 'gt' | 'lt' but wonder if this is the way. Anyway I tried Die_Modifier_Comp ~ 'gt' | 'lt' | '' and it dies.

    3 - Returned structures

    I put :default ::= action => [name,values] and I see that my subs where I return a hashref are modified and the actual return structure is \["Dice_Expression", { die_type => "1d4", rolls => [2] }] if I remove name from the default action it eliminates the "Dice_Expression" part. Anyway a reference to an arrayref is returned and then I have to write ugly things like: $$$new[1]->{rolls}->[0]

    How can I use name in a profitable way? There is a way to simplify returned structures (well I can unwrap it at the begin of the sub..)?

    Below my actual code.

    Thanks for reading


    PS January 16 2021 I published A dice roller system with Marpa::R2

    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.
convert tags to punctuation
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 12, 2021 at 19:49

    I have a large text file to process. When I view it with the 'more' filter I see a lot of these tags: <91> <92> <93> <94> <97> I can see from the context they are of a grammatical nature. Is there a nice way to convert these tags into punctuation marks etc?

Perl AJAX jQuery, js file
4 direct replies — Read more / Contribute
by monx663
on Jan 11, 2021 at 07:29
    This is not exactly a Perl question but, I'm using Perl as the backend programming language that creates HTML so...

    I am incorporating AJAX on a CMS written in Perl which has been stable for years. One of the backoffice pages of this CMS, shows a list of items that expose actions that can be carried out on this item. One of these actions is Activate/Inactivate. This is just an icon wrapped around that would call the right Perl script on the server and switch the items' status. I am trying to do this with AJAX/JSON jQuery inline, rather than enforcing a full page reload with the traditional href link to a CGI script.

    I have written a script on the server that responds to AJAX called with jQuery and completes the desired action and returns dynamic results that update the corresponding hardcoded (div2log) DIV element of the page that called it. <DIV id="div2log"></DIV>

    What I would like to do is include the JSON/jQuery stuff in a .js (Javascript) file on the server and only include references to this file where jQuery/AJAX is needed for any item.

    I have created a js file that contains:

          $.ajax({url: "/cgi-bin/", success: function(result){

    But I am not sure how to reference it, and pass it the params that I would have passed to a script using /cgi/ and I am not sure how to pass it the HTML ID of the DIV that it must update with the visual result of its action on the server.

    Does my question make sense?

Should non-filename glob() results still be tainted?
2 direct replies — Read more / Contribute
by kcott
on Jan 09, 2021 at 21:13

    The documentation for glob() has:

    "If non-empty braces are the only wildcard characters used in the glob, no filenames are matched, ..."

    In "perlsec: Taint mode", the long list of examples has (near the end):

    @files = <*.c>; # insecure (uses readdir() or similar) @files = glob('*.c'); # insecure (uses readdir() or similar) # In either case, the results of glob are tainted, since the list of # filenames comes from outside of the program.

    I'm an extremely infrequent user of glob(); however, I thought it could be useful in a test I was writing yesterday. The code looked something like this:

    #!perl -T use 5.032; use warnings; ... my @prefixes = qw{...}; my @suffixes = glob '{,x}{,y}{,z}'; ... for my $prefix (@prefixes) { for my $suffix (@suffixes) { my $name = join '_', $prefix, split //, $suffix; # run is(...) test with $name here } }

    I got a "tainted" message. This code fixed it:

    my $tainted_name = join '_', $prefix, split //, $suffix; $tainted_name =~ /^(.+)$/; my $name = $1; # run is(...) test with $name here

    I'm wondering if not tainting the values returned by a non-filename glob() would be a useful enhancement to Perl. I throw this open for discussion.

    — Ken

Is typeglob feature really useful?
4 direct replies — Read more / Contribute
by xiaoyafeng
on Jan 09, 2021 at 12:48

    As we all know, Perl support same name but different type, that means $foo and @foo could be both exist without any violation.

    This sounds a smart and nature feature, but from time to time, I suspect if it's useful. During my life, I've never defined 2 different type of variables with same name. Considering perl have to define a special(or maybe huge and complex ) data struct to store glob, if we discard this feature, maybe perl could be faster and simpler?

    Just a thought jump into my head, Please enlighten me. Thanks

    EDIT: modify title as LanX point out.

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

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 chanting in the Monastery: (7)
As of 2021-01-16 15:33 GMT
Find Nodes?
    Voting Booth?