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.

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.

Post a new question!

User Questions
When not to use taint mode
5 direct replies — Read more / Contribute
by Bod
on Jun 12, 2021 at 15:09

    A few times recently in the Monastery I have noticed mention of taint mode

    A long time ago I first came across taint mode and decided it is far too difficult to understand...I've since looked again and it doesn't appear anything like as mystical as it once did. That's what happens when one improves of course.

    I have never used taint mode so have no idea of the ease or otherwise of actually using it. It seems from this poll that most others don't use it either. So why not? Is it that taint mode is actually difficult to use or are there reasons to keep it switched off as it is by default?

    Do you have any advice on the topic?

IO::Async::PID works fine in SSCCE, fails randomly in real app, how to debug?
No replies — Read more | Post response
by vr
on Jun 12, 2021 at 09:25

    Edit. Please ignore. I forgot there's already "1 while waitpid(-1, WNOHANG) > 0;" added long time ago to obscure part of application to reap rarely spawned children, should re-write it now using e.g. a no-op IO::Async::PID's on_exit handler. Sorry.

    The OS is Windows, there's existing IO::Async-based, somewhat complex and clumsy app, which I want to extend. At some point in workflow, lists of file names arrive, in batches up to hundreds of items, but usually, say, 1-20. What I want to insert, is to process each file invoking external CLI tool, which takes, say, 5 to 60 seconds per file. It is to be done asynchronously by a few (2-5, I'll see when I get to observing real load) workers, and when whole current batch is ready, I want to get control back and proceed with workflow as it exists now.

    Because it's Windows, the recommended way with IO::Async::Process won't work, it wants real POSIX fork. "OK", I thought, I'll fire "system 1, @args" per file, and PID will be used to add IO::Async::PID watcher to the loop.

Replacing crypt() for password login via a digest - looking for stronger alternative
4 direct replies — Read more / Contribute
by davebaker
on Jun 11, 2021 at 15:14

    Yikes. Another 8-1/2 billion passwords have been leaked.

    Have a login system for my web app that has a couple hundred users. To log in, a user enters a password, the submitted password is run through my authentication script that uses crypt() and compares the result to a hashed string (i.e., a digest) stored in a text file on my server (because crypt() had created that digest when the user first created his or her account). If the crypt() result is the same as the digest, we have a match, so c'mon in.

    I've done enough research to see that such a system is a commonly-used one and has the advantage of not storing passwords in plain text, or even storing passwords at all, but that crypt() uses an encryption method that isn't very strong, at least nowadays.

    So I'm thinking there is a security vulnerability in the event a black hat were to obtain the plain text file by breaking into my server. Then the black hat runs a rainbow table against each user's digest to find a password that produces that same string. Then the black hat takes the user's password to the user's bank web site and uses that same password to empty the account, because so many people use the same password for multiple websites. It's not so much the user's information on my website that's confidential, it's the empty-the-bank-account scenario that's troubling.

    This issue always has been present with the use of a digest for purposes of password checking, but I'm thinking it becomes more of an issue when a couple billion more possible passwords are released that can be used to make the rainbow table more effective. Hence the risks of damages to my users has gone up, and my risk of getting sued has gone up. Do you agree?

    So I'm thinking that it would be good to replace:

    grant_website_access() if ( $password_entered_on_web_form eq crypt( $u +ser_specific_hash_stored_in_text_file_on_server, $password_entered_on +_web_form );

    with

    grant_website_access() if ( $password_entered_on_web_form eq something +_stronger_than_crypt( $user_specific_hash_stored_in_text_file_on_serv +er, $password_entered_on_web_form );

    An article on Password Storage with Salted Hashes recommends Crypt::SaltedHash, with an example that seems to use the module's methods to achieve the same effect as my code. The author also recommends the use of SHA-512 with Crypt::SaltedHash rather than the considerably less secure SHA-1 or MD-5.

    That's a good solution, it appears, to my perceived problem. I've checked threads back through 2012 here on PM and find none better, although Authen::Passphrase::BlowfishCrypt is intriguing.

How to count the vocabulary of an author?
4 direct replies — Read more / Contribute
by karlgoethebier
on Jun 11, 2021 at 07:12

    I have no serious idea for the moment. And done nothing so far. Background is that Kurt Schumacher claimed that Goethe had a vocabulary of about 29.000 words and Adenauer only had a vocabulary of about 500 words.

    Update: Thanks to all for the kind and inspiring replies. I guess Lingua::Stem is the way to go. I‘ll open another thread about tokenizing.

    «The Crux of the Biscuit is the Apostrophe»

AnyEvent::HTTPD -> Extra Callback after response?
2 direct replies — Read more / Contribute
by sectokia
on Jun 10, 2021 at 21:51
    Hi Monks, I cannot work out why in this code the callback sub is called twice. The response goes to the client after the timer expires the first time, but then it triggers all over again. Code:
    use strict; use warnings; use AnyEvent::HTTPD; my $h = AnyEvent::HTTPD->new(port => 8123);; my $timer; $h->reg_cb ( '/test' => sub { my ($httpd,$req) = @_; $req->respond({ content => ['text/plain', sub { my ($data_cb) = @_; return unless $data_cb; print "Setting timer...\n"; $timer = AnyEvent->timer(after => 5, cb => sub { print "Sending response...\n"; $data_cb->("Hello"); $data_cb->(); }); }] }); }, ); my $c = AnyEvent::condvar; $c->recv();
    Output:
    Setting timer... Sending response... Setting timer... Sending response...
    I was expecting the sub to only be called once. But it ends up being called a second time? Is there any way to avoid this? Thanks!
a look at Sub::Genius with the debugger, and use v in 2021
No replies — Read more | Post response
by Aldebaran
on Jun 10, 2021 at 20:51

    I was looking at my normal youtube feed when Leon Timmermans came up with a presentation about Raku. (Certainly interesting, and I have questions for him, but not now.) I soon realized that the zoom convention was happening, and that I could get it in essentially real time on youtube. I have them on as I go about my business, and B Estrade's talk comes on. I went about cleaning the kitchen at the start, but once it started into graph theory, I got very interested, and gave it my full attention. As things started cooking, the moderator chimed in that five minutes remained, and the presenter was left to rush through slides, to my, and seemingly, his dismay. He didn't get to running code, but I was interested enough to see what I could dig up. I feel like there was a second half to the talk that I would gladly hear. I tried to fill in the gaps by working some code, and I would like to post sources, output and questions.

    Thanks to presenters. I've seen several and might need half a year to see them all. I appreciate your service. Thanks also for comments,

Help! dmake error Win10
4 direct replies — Read more / Contribute
by Sanjay
on Jun 10, 2021 at 08:15

    dmake error while trying to install a module. Windows 10 Home. ActiveState Perl 5.26. Screen ...

    C:\ids\nm3\perl\ssan3-2.6.01>perl Makefile.PL Checking if your kit is complete... Looks good Generating a dmake-style Makefile Writing Makefile for ssan3 Writing MYMETA.yml and MYMETA.json C:\ids\nm3\perl\ssan3-2.6.01>dmake cp ssan3.pm blib\lib\ssan3.pm AutoSplitting blib\lib\ssan3.pm (blib\lib\auto\ssan3) Running Mkbootstrap for ssan3 () "C:\Perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "ssan3.bs" "C:\Perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- ssan3 +.bs blib\arch\auto\ssan3\ssan3.bs 644 "C:\Perl\bin\perl.exe" "C:\Perl\lib\ExtUtils\xsubpp" -typemap C:\Perl +\lib\ExtUtils\typemap ssan3.xs > ssan3.xsc "C:\Perl\bin\perl.exe" -MExtUtils::Command -e mv -- ssan3.xsc ssan3.c C:\Perl\site\bin\gcc.exe -c -IC:\ids\nm3/h -s -O2 -DWIN32 -DWIN64 + -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IM +PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fwrapv -fno-strict-aliasing -mms- +bitfields -s -O2 -DVERSION=\"2.6.01\" -DXS_VERSION=\"2.6. +01\" "-IC:\Perl\lib\CORE" ssan3.c "C:\Perl\bin\perl.exe" -MExtUtils::Mksymlists \ -e "Mksymlists('NAME'=>\"ssan3\", 'DLBASE' => 'ssan3', 'DL_FUNCS' + => { }, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);" C:\Perl\site\bin\g++.exe ssan3.def -o blib\arch\auto\ssan3\ssan3.dll - +mdll -s -static-libgcc -static-libstdc++ -L"C:\Perl\lib\CORE" -L"C:\M +inGW\x86_64-w64-mingw32\lib" ssan3.o "C:\Perl\lib\CORE\libperl526.a +" "C:\ids\nm3\lib\stssan3cl.lib" "-lmoldname" "-lkernel32" "-luser32" + "-lgdi32" "-lwinspool" "-lcomdlg32" "-ladvapi32" "-lshell32" "-lole3 +2" "-loleaut32" "-lnetapi32" "-luuid" "-lws2_32" "-lmpr" "-lwinmm" "- +lversion" "-lodbc32" "-lodbccp32" "-lcomctl32" -Wl,--enable-auto-imag +e-base ssan3.o:ssan3.c:(.text+0x263): undefined reference to `ezx113' ssan3.o:ssan3.c:(.text+0x95f): undefined reference to `ezx112' ssan3.o:ssan3.c:(.text+0x1003): undefined reference to `ezx111' ssan3.o:ssan3.c:(.text+0x1482): undefined reference to `ezx110' ssan3.o:ssan3.c:(.text+0x1984): undefined reference to `ezx108' ssan3.o:ssan3.c:(.text+0x2001): undefined reference to `ezx107' ssan3.o:ssan3.c:(.text+0x2533): undefined reference to `ezx105' ssan3.o:ssan3.c:(.text+0x29f2): undefined reference to `ezx104' ssan3.o:ssan3.c:(.text+0x2f00): undefined reference to `ezx103' ssan3.o:ssan3.c:(.text+0x33ed): undefined reference to `ezx102' ssan3.o:ssan3.c:(.text+0x3a1c): undefined reference to `ezx101' ssan3.o:ssan3.c:(.text+0x3fe3): undefined reference to `ezx100' ssan3.o:ssan3.c:(.text+0x4460): undefined reference to `ezx099' ssan3.o:ssan3.c:(.text+0x4c59): undefined reference to `ezx005' ssan3.o:ssan3.c:(.text+0x54f0): undefined reference to `ezx026' ssan3.o:ssan3.c:(.text+0x5b78): undefined reference to `ezx061' ssan3.o:ssan3.c:(.text+0x60c7): undefined reference to `ezx060' ssan3.o:ssan3.c:(.text+0x66b3): undefined reference to `ezx022' ssan3.o:ssan3.c:(.text+0x6c23): undefined reference to `ezx021' ssan3.o:ssan3.c:(.text+0x6f9a): undefined reference to `ezx002' ssan3.o:ssan3.c:(.text+0x716b): undefined reference to `ezx001' ssan3.o:ssan3.c:(.text+0x75d9): undefined reference to `ezx109' ssan3.o:ssan3.c:(.text+0x7b4d): undefined reference to `ezx106' ssan3.o:ssan3.c:(.text+0x8340): undefined reference to `ezx004' ssan3.o:ssan3.c:(.text+0x8b93): undefined reference to `ezx025' ssan3.o:ssan3.c:(.text+0x9450): undefined reference to `ezx003' ssan3.o:ssan3.c:(.text+0x9ca2): undefined reference to `ezx024' ssan3.o:ssan3.c:(.text+0xa44b): undefined reference to `ezx023' c:/perl/site/lib/auto/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.6.3/.. +/../../../x86_64-w64-mingw32/bin/ld.exe: ssan3.o: bad reloc address 0 +xae0 in section `.rdata' collect2: ld returned 1 exit status dmake.exe: Error code 129, while making 'blib\arch\auto\ssan3\ssan3.d +ll' C:\ids\nm3\perl\ssan3-2.6.01>
Doubley surprised by fat commas
6 direct replies — Read more / Contribute
by GrandFather
on Jun 09, 2021 at 17:43

    In a recent post I noticed on_success => => sub { and thought, "huh, that's gotta hurt". To my surprise the extra => didn't have the effect I expected. I did a little experimenting:

    use strict; use warnings; showParams(fat => => 'comma'); showParams('real', , 'comma'); showParams('explicit', undef, 'comma'); sub showParams { my @params = @_; for my $param (@params) { if (!defined $param) { print ">undef<\n"; next; } if (ref $param) { print "'", ref $param, "'\n"; next; } print "'$param'\n"; } printf "\n"; }

    Prints:

    'fat' 'comma' 'real' 'comma' 'explicit' >undef< 'comma'

    I expected to see the >undef< line for each version of the call to showParams. What am I missing?

    perl -v reports: This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Not printing the values outside the while loop
5 direct replies — Read more / Contribute
by suvendra123
on Jun 09, 2021 at 12:17
    my @result; my @result1; my @result2; my $b; my $c; my $d; my $ifile51 = '../test.txt'; my $ofile51 = 'seq.txt'; open (my $ifh51, '<', $ifile51) or die $!; open (my $ofh51, '>', $ofile51) or die $!; while(my $line51 = <$ifh51>) { # my $line51 = $_ if /\bbist_mode\b/; @result = grep (/bist_mode/, $line51); @result1 = grep (/mode_sel/, $line51); @result2 = grep (/mem_type_sel/, $line51); $b = join("_",@result); $b =~ s/,([^,]*$)/$1/; $c = join("_",@result1); $c =~ s/,([^,]*$)/$1/; $d = join("_",@result2); $d =~ s/,([^,]*$)/$1/; print $b; print $c; print $d; } print $b; print $c; print $d;

    This code prints the value of b,c,d inside while loop but not outside while loop , what may be the problem ?

    The text file contains

    bist_ctlr_clk_bistctlr,

    bist_ctlr_rst_bistctlr_n,

    bist_ctlr_serial_in_system,

    bist_ctlr_serial_out_system,

    bist_ctlr_shift_en_system,

    bist_ctlr_global_bbad,

    bist_ctlr_global_repairable,

    bist_ctlr_bist_mode,

    bist_ctlr_mem_type_sel,

    bist_ctlr_mode_sel,

    bist_ctlr_memsafe,

    bist_ctlr_sif_reg_en_system,

    bist_ctlr_sif_load_en_system,

    bist_ctlr_sif_update_en_system,

    bist_ctlr_mem_atpg_mode,

    bist_ctlr_flash_data_select,

    bist_ctlr_flash_repair_data,

    bist_ctlr_bend,

    Outside the loop it should print

    bist_ctlr_bist_mode

    bist_ctlr_mem_type_sel

How to syntax-check Catalyst code which throws 'Invalid CODE attributes' errors?
3 direct replies — Read more / Contribute
by LittleJack
on Jun 08, 2021 at 21:33

    I'm having a problem doing perl -c on files which use Attributes.

    The error messages are like Invalid CODE attributes: Chained('/') : PathPart('foo') : CaptureArgs('0') because of the Attributes used in some subs in the file.

    I understand this is something to do with Moose and a somewhat experimental feature?

    Is what I need some other command flag to add to my perl -c command? Or is there some library I can include with -I when I run the syntax check, which will whitelist this feature? Or really just any way to get past this issue and find more low-level problems like a missing comma.

    TIA


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":