Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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.


    on Daxim's request



    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.

Basic but stupid problem i cannot wrap my head around
3 direct replies — Read more / Contribute
by baxy77bax
on Aug 06, 2020 at 04:57

    so the problem is the folloving:

    perl -le '$t="a/b"; if ($t =~/^(.*?)\//){$z=$1}elsif($t=~/\/(.*)/){$z= + $1} print $z' #prints a perl -le '$t="/b"; if ($t =~/^(.*?)\//){$z=$1}elsif($t=~/\/(.*)/){$z= +$1} print $z' #prints nothing
    it is probably something stupid , as i am quite tired but why isn't the second case being evaluated (or it is but why is it returning 0 )



Tk pop-up if condition is met
2 direct replies — Read more / Contribute
by IB2017
on Aug 05, 2020 at 17:18

    Is it possible to allow a popup in a text widget only if a condition is met, i.e. if a text has been selected? This is the code I have so far, which creates a popup, however, it checks if something has been selected only agter its creation.

    use strict; use warnings; use Tk; use Tk::Text; my $mw = tkinit(); my $text = $mw->Text()->pack(); $text->insert('end',"This is my first line\n"); $text->insert('end',"This is my second line\n"); PupupTextWidget($mw, $text); $mw->MainLoop(); sub PupupTextWidget{ my ($mw, $obj) = @_; my $messagePopupSave; if ($^O eq 'MSWin32'){ $messagePopupSave="Do something (ctrl+s)"; }else{ $messagePopupSave="Do something (cmd+s)"; } my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>$messagePopupSave, -command=>[sub { my $UserInput=$obj->getSelected; print $UserInput; }, $obj,]], [qw/command Copy/, -command=>['clipboardCopy', $obj,]], ]); $obj->menu($menu); return $obj; }
Looking for alternative for IPC::Shareable (or increase size)
7 direct replies — Read more / Contribute
by DomX
on Aug 05, 2020 at 16:55
    Hey Monks!
    I'm having a hard time today. I almost finished my program with over 9000 lines, but have one problem:

    Communication between my worker (forked unit) and master (GUI unit) has a size issue: (worker fills shared array, master reads content into not shared array and cleans shared array.)
    Length of shared data exceeds shared segment size at ./ line 1210.
    Buffer size is declared to be "65536". (No idea of unit, I think it's bytes.) This happens on one array element, when the containing string is longer than 65536.

    What I want to know:
    - is there a possibility to increase the size?
    - is there an alternative function, which allows me to share (bit long) text data between processes, without writing to disk? (Writing to Sqlite would decrease speed on this step extremely)

    If you don't know something like this, the only idea I have left is to make a Sqlite database "transfer", with just one column "data", and each row contains one string of my array. Many forks writing to it (slow...) and master reading and cleaning this table, just to prepare it to be saved in correct table and correct columns...
Scriptsock does not exist??
2 direct replies — Read more / Contribute
by marknher
on Aug 04, 2020 at 19:26

    Hi Monks!

    I have a perl sript ticketing system that is admittedly old but works perfect for our company. Recently, we started getting ERROR 503 messages on our website and it goes away in about 30 minutes. I reached out to the server admins and they responded with the following

    While revising this case our administrators have noticed you script is using socket connections which not completely closed and error similar to arises:

    AH02833: ScriptSock /var/run/cgid.sock.23916 does not exist:

    since the script attempts to reference to previous non existing socket previously used and the error noticed arises. We can not offer debugging of the scripts although and you should check with your website developers what socket connections are used, how are these closed and why the processes reference to an old connection so they could avoid that for your script.

    I've Googled around about this and went through my scripts trying to figure out anything that has changed but I come up blank. Anyone have any clues on what this really means so that I can hunt down the problem and fix it?

    Thanks, Mark T.

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

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.

PerlMonks Discussions
Preview neither truncates nor warns
2 direct replies — Read more / Contribute
by hippo
on Aug 05, 2020 at 04:38

    Reading Re^10: XS.c: loadable library and perl binaries are mismatched (got handshake key 0xc100000, needed 0xc180000) I was encouraged to confirm what rgren925 reported. I constructed a reply with about 120kB in it and used the Preview button to check it. All of it was rendered and there was no warning (that I could see) that it was over the size limit for posting. When it was subsequently submitted it still rendered fine and it was only on a further navigation to the same node that it did truncate to ~64kB as I expected.

    This is not great from a UX perspective. The preview should either warn about the size or truncate it like the final submission would do or (ideally IMHO) both. The full text could still be retained in the textarea for ease of editing.


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 exploiting the Monastery: (5)
As of 2020-08-07 09:23 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (43 votes). Check out past polls.