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

Donations gladly accepted

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
9 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
German Perlmongers Online Meeting
on Aug 04, 2020 at 12:59
0 replies by LanX
    @ All German speakers here:

    Next German PM Online Meeting in (cough) 30 minutes.


    Hallo Perlmongers aus den deutschsprachigem Raum,

    Heute, am Dienstag, den 4. August 2020, um 19:30 Uhr ist German-PM Online-Treffen im Jitsi.

    Dank Corona wurde das Online-Treffen mehrfach in Erlangen und Frankfurt ausprobiert. Der Wunsch wurde geäußert, das online neben den Treffen vor Ort weiterzuführen.

    Nimm an der Besprechung teil:

    I'm not the organizer, but I'll use this thread for future announcements.


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

Strawberry Perl-5.30.3 is available
on Aug 02, 2020 at 09:02
1 reply by syphilis

    Just noticed that Strawberry Perl-5.30.3 is now available.
    The date given there is 2020-07-13, but I know it wasn't available earlier today. (Looks like the date is the date that perl was built - not the date at which the distro became available.)

    Hopefully, that indicates that 5.32.0 might not be too far away.
    Actually, I build my own perls on Windows and therefore don't rely on the Strawberry project for perl. It's still a very handy reference for me, but.
    And I do look forward to using the updated gcc compiler that usually accompanies new Strawberry Perl major releases.
    Since the mingw-w64 project stopped providing recent builds of gcc (as of a couple of years ago), I've come to rely on Strawberry for my gcc upgrades.

    Anyway ... just thought it was worth mentioning ... and looking forward to a 5.32.0 release soon, with (fingers crossed) gcc-9 or gcc-10.

TK Listbox: scrolling with keys/mousewheel
1 direct reply — Read more / Contribute
by Ratazong
on Aug 04, 2020 at 03:57

    Dear monks

    I'm struggeling with creating a scrolled listbox in Tk: the code below works, however I'm not able to scroll with the arrow-keys nor with the mouse-wheel. Do I have to bind the events myself and code the related actions? Or am I just missing something?

    Thanks for your help! rata

    sub selectProjectDialog_newtest { $mw = shift; # store the main window my @project_choices = split(" ","Project1 Project2 Project3 Proje +ct4 Project11 Project12 Project13 Project14 ") ; my $projectSelection_tl= $mw->Toplevel( ); $projectSelection_tl->title("Select the project:"); $projectSelection_tl->Label(-text => 'Select the project Id:', + )->grid(-row => 5, -column => 10, -sticky => "w"); my $scrolled1 = $projectSelection_tl->Scrolled ("Listbox", -scrollbars => "se", -width => 50, -height => 4, -selectmode => "extended") ->grid(-row => 10, -column => 10, -columns +pan => 10, -rowspan => 10); $scrolled1->insert ("end", @project_choices); }

Effect of redirecting output to /dev/null on $? value
2 direct replies — Read more / Contribute
by Special_K
on Aug 02, 2020 at 20:14

    For reference, this is somewhat of a follow up question to a question I asked previously:

    What is the impact on the value of $? if the output of an application is redirected to /dev/null? This is running under RHEL7.

    For example, suppose I have a perl script that calls a compiled executable that seg faults:

    `my_executable_that_seg_faults`; my $exit_value = $? >> 8; my $signal_num = $? & 127; my $dumped_core = $? & 128; printf("return value is %d\n", $?); printf("exit_value = $exit_value\n"); printf("signal_num = $signal_num\n"); printf("dumped_core = $dumped_core\n");

    Running the above code produces the following output:

    return value is 11 exit_value = 0 signal_num = 11 dumped_core = 0

    This output is consistent with what I would expect based on information found here related to the $? variable:

    However if I change the executable call above to the following:

    `my_executable_that_seg_faults > /dev/null`;

    The following output is produced:

    return value is 35584 exit_value = 139 signal_num = 0 dumped_core = 0

    The above output is significantly different even though the application still seg faulted. Here are my questions:

    1. Why did the value of $? completely change when I added the output redirect to /dev/null but kept everything else the same?

    2. Does the value of $? in the second case still contain the same information but encoded differently?

    I created a different application with an intentional segmentation fault and called it using the above perl script. It produced the exact same output, suggesting that this behavior is not dependent on the behavior of the called application.

Getting code-ref of anonymous caller
1 direct reply — Read more / Contribute
by LanX
on Jul 31, 2020 at 11:13
    As the following demo shows is caller(1) reporting the name of the calling sub + package.

    In the case of a named subroutine one is able to get the code-ref of the caller by inspecting the STASH.

    But this doesn't work with anonymous subs.

    Caller claims they are part of the stash (here main::__ANON__ ) but accessing the associated code-ref fails. It most likely a newly autovivificated code-ref.

    Any better way to get the callers code-ref?

    First the output

    CURRENT SUB: CODE(0x24c9198) main::upper CODE(0x24c9198) CURRENT SUB: CODE(0x24e8568) main::__ANON__ CODE(0x24c0580) # <--- OOPS

    Here the demo:

    use strict; use warnings; use Data::Dump qw/pp dd/; use feature "current_sub","say"; sub lower { my %caller; package DB { @caller{ qw/ package filename line subroutine hasarg +s wantarray evaltext is_require hints bitmas +k hinthash / } = caller(1); }; my $caller_name = $caller{subroutine}; my $caller_ref =\&{$caller_name};; say $caller_name," ",$caller_ref; } # --- normal sub upper { say "CURRENT SUB: ",__SUB__; lower( "UPPER" ); } upper(); # --- ano sub my $ano = sub { say "CURRENT SUB: ",__SUB__; lower("ANNO"); }; $ano->();

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

no ppm on ActiveState perl?
2 direct replies — Read more / Contribute
by guthrie
on Jul 30, 2020 at 20:39
    I am trying to port a perl program from linux to Windows, and it uses XML::XPath Trying to load it, most advice seems to be to use ppm, but AS doesn't seem to provide that anymore - is that right? And "pip install" fails, as I don't have a pip in the ASPerl installation. Trying to install it from CPAN gives lots of dmake errors like below.

    As does "cpan install"; fails with:

    " MANWAR/XML-XPath-1.44.tar.gz E:\PLang\ActivePerl\bin\perl.exe Makefile.PL INSTALLDIRS=site -- O +K Running make for M/MA/MANWAR/XML-XPath-1.44.tar.gz x[91m[DMAKE] error: the following arguments are required: command. +.[0m ... e:\Plang\Python\python36\scripts\dmake.exe -- NOT OK
    Lots of reports on this sort of thing, but I didn't find anything simple that works yet. Any hints? Should I dump AS perl and move to Strawberry? Please excuse any novice confusion here!
Use cases for 'sub Pckg::func { }' ?
4 direct replies — Read more / Contribute
by LanX
on Jul 30, 2020 at 19:08
    It's possible to define a fully qualified sub by adding the package to the name.

    So I played around with sub X::foo and noticed that sub resolution happens in the surrounding package.

    That looks consistent to me, it's analogue to BEGIN{ *X::foo = sub { } } where the anonymous sub carries its package context around.

    Hence calling foo() will work while bar() fails, because Data::Dump wasn't imported into X::

    use strict; use warnings; use Data::Dump qw/pp dd/; sub X::foo { pp(\@_) }; BEGIN { *X::baz = sub { pp(\@_) } }; package X; sub bar { pp(\@_) } ; foo(1..3); # [1, 2, 3] baz(1..3); # [1, 2, 3] bar(4..6); # Undefined subroutine &X::pp +called

    Question: What are the use cases of that pattern?

    The only thing which comes to mind is monkey patching a sub in another package without adding inner helper functions into that package.

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

help with XS pointers
3 direct replies — Read more / Contribute
by Bpl
on Jul 30, 2020 at 18:01
    Hi monkers, in these days I was building an XS library, based on the librtlsdr library ( github link: ) for now, some functions works fine but the "rtlsdr_open" call gives me some problems. For starting the code (from the github library) referred to the call is:
    RTLSDR_API int rtlsdr_open(rtlsdr_dev_t **dev, uint32_t index); # where rtlsdr_dev_t is initialized as: typedef struct rtlsdr_dev rtlsdr_dev_t;
    I think that my implementation of rtlsdr_dev is wrong, in the XS code I wrote
    int rtlsdr_open(dev, index) RTLSDRDevice_T **dev uint32_t index # where RTLSDRDEVICE_T is typedef rtlsdr_dev_t RTLSDRDevice_T;
    and from the TYPEMAP file the structure are declared as:
    now, the problem is that, when I run this code:
    use SDR::RTLSDR qw(:all); # my library my $serial_number = "00000001"; # from dmesg output my $index = rtlsdr_get_index_by_serial( $serial_number ); # it returns + 0, this is not an error value so I think is good my $device = rtlsdr_get_device_name( $index ); print rtlsdr_open( $device , $index)
    I have the following error:
    SDR::RTLSDR::rtlsdr_close: dev is not of type RTLSDRDevice_TPtr at sdr line 7.
    Now, I think that the result is related to some pointer error but also with:
    print rtlsdr_open( \$device , $index)
    I had the same error code. hope in some helps Thanks Edoardo M.
Project in Raku
3 direct replies — Read more / Contribute
by ovedpo15
on Jul 30, 2020 at 07:13
    Hello monks!
    Recently I started studying Raku. I didn't find a Raku community so I hope it's ok to ask those questions here.
    After studying Raku for a while I want to do some project using the PL. I want to implement a code coverage utility for Raku. I have some questions:

    1. I may be wrong but it looks like the Raku community is not so active. I want to get information about the community and I'm not sure where to start.
    2. Is there really a use/need of the code coverage utility for Raku? I came across with moarvm and it looks like it provides a way to create a coverage report.
    3. How should I try solving this issue?

    I'm just trying to understand the problem I'm trying to solve, before solving it.
Not understanding 2 sentences in perldoc
6 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 29, 2020 at 15:13
    The link to the documentation is

    "Similarly, a list assignment in list context produces the list of lvalues assigned to, and a list assignment in scalar context returns the number of elements produced by the expression on the right hand side of the assignment."

    I don't understand. Can you monks please explain to me and give me examples of what this sentence means?

    "Unlike in C, the scalar assignment operator produces a valid lvalue. Modifying an assignment is equivalent to doing the assignment and then modifying the variable that was assigned to."

    I don't get it either. Please clarify to me I beg.

Looking for a module that strips an HTML tag and its associated 'TEXT'
3 direct replies — Read more / Contribute
by nysus
on Jul 29, 2020 at 09:24

    I'm having a surprisingly hard time finding a module to strip out a given HTML tag along with the text it contains. HTML::TagFilter doesn't strip the text. HTML::Strip does not allow you to filter out only one kind of HTML tag (the <p>) tag for instance (it looks like it might do this but it doesn't, I tried). Looking for something nice and simple that doesn't rely on regexes.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

PERL for tool and testing automation
3 direct replies — Read more / Contribute
by tahirsengine
on Jul 29, 2020 at 09:08
    Hi, I am an engineer working in VLSI industry. I want to switch my job, but the job requirements also enlist the PERL scripting capability for verification. So is there any good tutorial that shows how that automation works? Like If I wrote a module and test bench in Modelsim, and I want to automate the testing, how will I go about that using PERL script? I have learned PERL, but I have no idea how to just about this specific problem. Thanks in advance
A locale independent sprintf?
3 direct replies — Read more / Contribute
by swl
on Jul 28, 2020 at 20:20

    Is there an sprintf implementation available for Perl that is independent of any numeric locale settings? i.e. where sprintf "%.2g", 3.1415926 returns 3.14 and not 3,14 on locales that use a comma as the radix character.

    For context, I recently hit issues with a Gtk2 interface to an application was setting the numeric locale to match a user's settings. The application uses sprintf to reduce the numeric precision of values to use as hash keys for a simple index, which then had knock-on effects when the index keys were used numerically. There were other locale effects, but that was the main one.

    That specific case is now avoided since I discovered Gtk2->disable_setlocale, and I do realise that numeric locales affect more than just sprintf, but it might still be useful to have a locale independent version.

    I found nothing when checking metacpan, but there look to be external libraries that allow one to specify a locale as an argument.

Split fake, an emulation of split
2 direct replies — Read more / Contribute
by bojinlund
on Jul 31, 2020 at 07:45


    I found an error in the documentation of split Function Split, bug or error in the documentation?.

    Had problems to understand the documentation of split. Decided to do an emulation of split to get a better understanding of split.

    Discovered that split does not behave like a normal subroutine Split does not behave like a subroutine.

    This is my try on an emulation of split. I hope this can help someone!

    Module Fake::Split

    The module implements split using the match operator m{}. It also includes utilities to debug the emulation.

    Used terms:
    Split divides a string in fields and separators. The /PATTERN/ matches the separators. The parts before, between and after a separator are the fields.
    sub splitF_match_pos

    sub splitF_match_pos returns a list with the position (pos) in the string for the start and end of matches. The list contains groups of pos with pos start and pos end of field, and a reference to an array. The array contains pos for start and end of separator and optional for each capture group, the start and end.

    sub splitF_case

    Identifies the patterns which needs special treatment in split.

    sub splitF_pos

    This routine handles split specific things. It uses the more generic splitF_match_pos.

    sub splitF_pos2txt

    The output is a textual presentation of the output from sub splitF_pos.

    sub splitF_pos2list

    Create a list of strings from the output of sub splitF_pos. The output is (should be) the same as that from split.

    sub splitF_test($;$$)

    Can be used to test the split emulation. See below!

    sub splitF($;$$)

    This is the emulation of split.

    If PATTERN, the first argument to split, is a match operator /STRING/ it must be replaced with qr/STRING/, a compiled regular expression.

    The syntax split /PATTERN/ and split are not supported

    My test of the module

    I have based my tests on the file t/op/split.t in the Perl source code distribution and on the examples in split.

    This script uses most of the /PATTERN/,EXPR,LIMIT combinations used in split.t. I had to change all /STRING/ to qr/STRING/. (I have not found any way to emulate split's way to delay the evaluation of its first argument).

    In the line is_deeply splitF_test(" ", "a b c"); returns splitF_test a suitable input to is_deeply.

    The output from splitF_test consists of two anonymous arrays, one with the output from the emulation and one from split, and a string with a dump of the argument /PATTERN/,EXPR,LIMIT

    My observations and questions

    The use of the Perl variable $#+

    It is important to use $#+ together with @- and @+. See my sub splitF_match_pos above.

    Inconsistency between m{} and split

    The need for this in sub splitF_pos2list

    if ( $field_start == $field_end && $sep_aref && $field_start == $sep_aref->[0] && $field_start == $sep_aref->[1] ) { info('SKIP intermediate field+separator, both are empty'); next; }
    indicates an undocumented inconsistency!?

    Arguments used together with Regexp Quote-Like Operators

    I have several times found limitations on what can be an argument to Regexp Quote Like Operators.

    One example is

    # while ( my $rv = $$str_ref =~ m{$pat_re}gc ) { does not work # but this works: my $str = $$str_ref; while ( my $rv = $str =~ m{$pat_re}gc ) {

    Are those limitations documented anywhere?

    A split function which behaves like a perl subroutine?

    The current split is a list operator with a lot of surprises and special cases.

    What about a parallel alternative, not so optimized implemented, which behaves like a normal subroutine. Perhaps a string study function with the arguments: pattern, reference to a string and returning a list with positions (not splitting the string in sub-strings). An optional parameter could be used to select special cases.

    A string study iterator is also useful.

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 rifling through the Monastery: (4)
As of 2020-08-04 19:29 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (33 votes). Check out past polls.