Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
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
6 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.

Out-of-the box Perl version - lowest common denominator
8 direct replies — Read more / Contribute
by kcott
on Jan 15, 2021 at 00:00

    G'day All,

    At $work, we're currently coding to Perl 5.16.0 as a minimum version: our clients are expected to have this version available to be able to run our software.

    We are considering increasing that minimum version. Doing so has been agreed in principle. However, we're scratching our heads a bit, trying to determine what a practical new version might be.

    By out-of-the box, I'm talking about what's available either as a new installation, or through standard updates through package managers. I'm not referring to what's possible by manual builds or using installation software (such as Perlbrew).

    As an example, I've quite recently updated Cygwin, which gives me:

    $ /usr/bin/perl -v | head -2 | tail -1 This is perl 5, version 30, subversion 3 (v5.30.3) built for x86_64-cy +gwin-threads-multi

    I have also installed a few Perl versions using Perlbrew:

    $ perlbrew list perl-5.33.5 * perl-5.32.0 perl-5.30.0

    So my answer to this question would be: "Cygwin: 5.30.3".

    I added "lowest common denominator" because, in practical terms for the current exercise, it's more important to know "ABC Linux: 5.20.0" than "XYZ Linux: 5.32.0".

    Your feedback on this would be very much appreciated. Thanks in advance.

    — Ken

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.

hex numbers
5 direct replies — Read more / Contribute
by LloydRice
on Jan 14, 2021 at 08:25
    I'm trying to do something that is probably stupidly simple, but it's just not working. I have a string with some decimal digits and some uppercase A..F. The string does NOT begin with "0X". I am simply trying to get the hex value into a variable. I've tried various prefixes, sprintf with various formats, pack, unpack, and a few more things. It's just not working ???
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?

Limit on number of nodes in a Tk::Tree?
3 direct replies — Read more / Contribute
by parv
on Jan 14, 2021 at 00:31

    Is there a limit on number of nodes a Tk::Tree can have? (I had tried to search for this but came up with useless results.) Or, why would a Tk::Tree not completely render a Tk window?

    I was trying to locate very fat directories on MS Windows 10 (modied code at the end), but the Tk window stopped updating after some entries. The output from &buildSubTree ...

    sub buildSubTree { ... #printf qq[Fetching data for %s ...\n], $path; foreach my $dir ( sort readdir $DH ) { ... my $annotation = annotate( $path , $size , $dirs , $files ); warn qq[$annotation], "\n"; $tree->entryconfigure( $node , '-text' => $annotation ); ++$stack->[-1]; } closedir $DH or die qq[Cannot close "$path": $!\n]; pop @$stack; printf( "=== %s\n", annotate( $path, $sizeTotal, $fileCount, $dirCo +unt ) ); return ( $dirCount , $fileCount , $sizeTotal ); }

    ... shows that the program does go through the whole tree of C:/Users/<userid> without much of any issues. There were no obvious Windows error dialogs or error messages from Perl or Tk.

    In the end, I used the text output instead of GUI to find the fat directories.

    I ran the following program with Starwaberry Perl 5.32.0 & Tk 804.035 (with MAX patch applied) in Powershell 7.0.1.

Time::ParseDate - Strawberry PERL 5.32 on Win 10
2 direct replies — Read more / Contribute
by FFSparky
on Jan 13, 2021 at 14:56

    All trying get up to a current version of PERL / Strawberry PERL 5.32 on my new Win 10 system.

    I cannot get Time::ParseDate to install as the test fail.

    As suggested I have set the TZ environment variable in my command window to TZ=PST8PDT

    I'm tryin to force it and skip the test and the command I am running is: cpan -fTi Time::ParseDate

    But it won't install:

    cpan -fTi Time::ParseDate Loading internal logger. Log::Log4perl recommended for better logging CPAN: CPAN::SQLite loaded ok (v0.219) Database was generated on Wed, 13 Jan 2021 20:20:07 GMT CPAN: Module::CoreList loaded ok (v5.20200717) Running install for module 'Time::ParseDate' CPAN: Digest::SHA loaded ok (v6.02) CPAN: Compress::Zlib loaded ok (v2.096) Checksum for C:\DEV_TO~1\PERL-6~1\cpan\sources\authors\id\M\MU\MUIR\mo +dules\Time-ParseDate-2015.103.tar.gz ok CPAN: Archive::Tar loaded ok (v2.38) CPAN: YAML::XS loaded ok (v0.82) CPAN: CPAN::Meta::Requirements loaded ok (v2.140) CPAN: Parse::CPAN::Meta loaded ok (v2.150010) CPAN: CPAN::Meta loaded ok (v2.150010) Configuring M/MU/MUIR/modules/Time-ParseDate-2015.103.tar.gz with Make +file.PL Checking if your kit is complete... Looks good Generating a gmake-style Makefile Writing Makefile for Time::ParseDate Writing MYMETA.yml and MYMETA.json MUIR/modules/Time-ParseDate-2015.103.tar.gz C:\Dev_Tools\PERL-64Bit\perl\bin\perl.exe Makefile.PL -- OK Running make for M/MU/MUIR/modules/Time-ParseDate-2015.103.tar.gz cp lib/Time/JulianDay.pm blib\lib\Time\JulianDay.pm cp lib/Time/DaysInMonth.pm blib\lib\Time\DaysInMonth.pm cp lib/Time/ParseDate.pm blib\lib\Time\ParseDate.pm cp lib/Time/Timezone.pm blib\lib\Time\Timezone.pm cp lib/Time/CTime.pm blib\lib\Time\CTime.pm MUIR/modules/Time-ParseDate-2015.103.tar.gz C:\DEV_TO~1\PERL-6~1\c\bin\gmake.exe -- OK Running make test for MUIR/modules/Time-ParseDate-2015.103.tar.gz Skip blib\lib\Time\Timezone.pm (unchanged) Skip blib\lib\Time\CTime.pm (unchanged) Skip blib\lib\Time\JulianDay.pm (unchanged) Skip blib\lib\Time\DaysInMonth.pm (unchanged) Skip blib\lib\Time\ParseDate.pm (unchanged) "C:\Dev_Tools\PERL-64Bit\perl\bin\perl.exe" "-MExtUtils::Command::MM" +"-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness( +0, 'blib\lib', 'blib\arch')" t/*.t t/datetime.t .. ok t/metdate.t ... skipped: It seems localtime() does not honor $ENV{TZ} +when set in the test script. t/order1.t .... 1/? # Failed test 'Europe/Moscow, DST permanent 2009' # at t/order1.t line 33. # got: '1257058800' # expected: '1257022800' # Failed test 'Europe/Moscow, DST permanent 2013' # at t/order1.t line 34. # got: '1369897200' # expected: '1369857600' # Looks like you failed 2 tests of 5. t/order1.t .... Dubious, test returned 2 (wstat 512, 0x200) Failed 2/5 subtests t/order2.t .... 1/? # Failed test 'Europe/Moscow, DST permanent 2013' # at t/order2.t line 31. # got: '1369897200' # expected: '1369857600' # Failed test 'Europe/Moscow, DST permanent 2009' # at t/order2.t line 32. # got: '1257058800' # expected: '1257022800' # Looks like you failed 2 tests of 5. t/order2.t .... Dubious, test returned 2 (wstat 512, 0x200) Failed 2/5 subtests Test Summary Report ------------------- t/order1.t (Wstat: 512 Tests: 5 Failed: 2) Failed tests: 3-4 Non-zero exit status: 2 t/order2.t (Wstat: 512 Tests: 5 Failed: 2) Failed tests: 3-4 Non-zero exit status: 2 Files=4, Tests=335, 2 wallclock secs ( 0.08 usr + 0.05 sys = 0.12 C +PU) Result: FAIL Failed 2/4 test programs. 4/335 subtests failed. gmake: *** [Makefile:851: test_dynamic] Error 2 MUIR/modules/Time-ParseDate-2015.103.tar.gz C:\DEV_TO~1\PERL-6~1\c\bin\gmake.exe test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports MUIR/modules/Time-ParseDate-2015.103.tar.gz Running make install for MUIR/modules/Time-ParseDate-2015.103.tar.gz Skip blib\lib\Time\ParseDate.pm (unchanged) Skip blib\lib\Time\CTime.pm (unchanged) Skip blib\lib\Time\DaysInMonth.pm (unchanged) Skip blib\lib\Time\JulianDay.pm (unchanged) Skip blib\lib\Time\Timezone.pm (unchanged) Appending installation info to C:\DEV_TO~1\PERL-6~1\perl\lib/perllocal +.pod MUIR/modules/Time-ParseDate-2015.103.tar.gz C:\DEV_TO~1\PERL-6~1\c\bin\gmake.exe install UNINST=1 -- OK Stopping: 'install' failed for 'Time::ParseDate'.

    The other question I am considering, Is Time::ParseDate still a good module or should I consider a diffent module. My concern here is I have several scripts that use this thus I may have a challenge ahead in modifying some old scripts.

    As always thanks in advance for your wisdom!

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?

    TIA!

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 lurking in the Monastery: (7)
    As of 2021-01-21 08:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?