Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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.

Quests
Monk Quips Quest
Starts at: May 01, 2023 at 08:00
Ends at: Dec 31, 2023 at 18:59
Current Status: Active
7 replies by erzuuli
    Esteemed Monk kcott has recently proposed an excellent idea.

    heretoforthwithstanding, we invite all monks to submit ideas for new monk quips!

    Your quip suggestion should include the following details:

    • Intended quip location: either XP Nodelet, Chatterbox, or Monkbar (that's the page header).
    • Text of quip.
    • Optional: background & foreground colours. If you include these, be sure they are nicely contrasting.

    .

poll ideas quest 2023
Starts at: Jan 01, 2023 at 00:00
Ends at: Dec 31, 2023 at 23:59
Current Status: Active
2 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
perl v5.38.0 is now available
on Jul 03, 2023 at 03:16
3 replies by Corion

    rjbs has released 5.38:

    Take my advice and live for a long, long time. Because the maddest thing a man can do in this life is to let himself die.

    — Miguel de Cervantes, Don Quixote

    We are happy to announce version 38.0, the first stable release of version 38 of Perl 5. In other words: v5.38.0 has been released, and this is good!

    You will soon be able to download Perl 5.38.0 from the CPAN at:

    https://metacpan.org/release/RJBS/perl-5.38.0/

    SHA256 digests for this release are:

    5c4dea06509959fedcccaada8d129518487399b7 perl-5.38.0.tar.gz 2e7b1c56c1f795e8173c83a52e91218ba05ee72c perl-5.38.0.tar.xz

    The full announcement is at https://www.nntp.perl.org/group/perl.perl5.porters/2023/07/msg266602.html.

perldoc.pl domain outage
on Jun 21, 2023 at 18:49
0 replies by hv

    BooK writes on perl5-porters:

    Just a PSA that the perldoc.pl domain has not been renewed and its registrant is sadly still out of contact. I have an option on the domain which will allow me to take ownership in a month, but until then (or the domain is renewed) it will not function. Robert has updated perldoc.perl.org to bypass the domain, so please update your links if you are still using perldoc.pl.

    -Dan

Supplications
Selecting DB
2 direct replies — Read more / Contribute
by frank1
on Jul 08, 2023 at 07:38

    Am having a problem with selecting users emails

    this is my DB

    DB USERS ID USERID EMAIL 1 XD4555 JOHNE@DEO.COM 2 JJKKKK JANE@DEO.COM 3 JJKKKK JANE21@DEO.COM FUSERS ID USERID USERID_IM 1 XD4555 JJKKKK 2 JJKKKK TYYUPPO
    my try
    my $AID = "XD4555"; my $query = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID WHERE (m.USERID_IM = ?)"); $query->execute($AID); my $user1 = $query->fetchall_arrayref(); my $query_other = $dbh->prepare("SELECT snd.EMAIL FROM FUSERS as m JOIN USERS as snd ON snd.USERID = m.USERID_IM WHERE (m.USERID = ?)"); $query_other->execute($AID); my $user2 = $query_other->fetchall_arrayref(); my $TotalEmails = $user1 + $user2; foreach my $em ( $TotalEmails ) { my $rez = join( ",", $em); print "$rez\n"; }

    now this is the results am getting, its random generated

    189822522692296

    this is the output i expect

    email@email.com, email@email.com
Where do I find the current PAUSE batch signing key?
1 direct reply — Read more / Contribute
by martin
on Jul 08, 2023 at 00:39
    Dear fellow monks,

    I am using Module::Signature and have configured my cpan shell to check signatures (check_sigs=1). This, however, will not just make cpan check module's signatures when unpacking packages, but also make it use my gpg command to check PAUSE checksums. This should perhaps be different configuration options, but I probably would turn both on anyways.

    Now Gnu Privacy Guard needs a signer's public key to verify a signed file like a PAUSE generated checksum. This signing key has recently been replaced. I have the old one (328DA867450F89EC) in my keyring but now need the new one (77576125A905F1BA). In https://www.cpan.org/modules/04pause.html , only the old one is present. On keyservers like pgp.mit.edu and keyserver.ubuntu.com the key is not to be found.

    Where else should I look? Without the key, I have to use cpan with signature checks completely turned off or it will not install anything. I don't like that. The idea of signatures was to make the toolchain safer against manipulated mirrors. The idea of signed checksums was to protect even packages not signed by their authors. I agree to all of this. Some new way of distributing PAUSE keys may have escaped me, though. Can you fill me in?

    Greetings,
    -Martin

extracting subroutine names (together with their packages) via PPI
5 direct replies — Read more / Contribute
by clueless newbie
on Jul 06, 2023 at 10:53

    Given the following chunk of code:

    #!/usr/bin/env perl use 5.032001; use warnings; my @packages; package Fee; push @packages,__PACKAGE__; sub one { say __PACKAGE__.q{::one}; }; package Fi; push @packages,__PACKAGE__; sub two { say __PACKAGE__.q{::two}; }; { package Foo; push @packages,__PACKAGE__; sub three { say __PACKAGE__.q{::three}; }; }; # End of package Foo! sub four { say __PACKAGE__.q{:four}; }; # Dump symbols for my $package (@packages) { no strict; my %stash = %{"${package}::"}; use strict; warn Data::Dumper->new([\$package,\%stash],[qw(*package *stash)])- +>Deepcopy(1)->Indent(1)->Maxdepth(3)->Sortkeys(1)->Dump(),q{ }; }; 1; __DATA__

    While Devel::Examine::Subs suggests:

    'one', 'two', 'three', 'four'

    dumping the symbols suggests

    \'Fee' ( 'one' => *Fee::one ) \'Fi' ( 'BEGIN' => *Fi::BEGIN, 'DATA' => *Fi::DATA, 'four' => *Fi::four, 'two' => *Fi::two ) \'Foo' ( 'three' => *Foo::three )

    My attempts to extract the full subroutine names using PPI have been failures. I can get the sub names and I can get the packages but not the needed relationship --- ie Fee::one, Fi::two etc. I would greatly appreciate knowing how to use PPI to extract the subroutine names in conjunction with their containing package.

    Thanks!

perl 5.38: can the body of a class declaration contain arbitrary code?
2 direct replies — Read more / Contribute
by jdporter
on Jul 04, 2023 at 16:41

    The doco saith:

    Fields may optionally have initializing expressions. . . . the expression can . . . see any other variables in scope.
    class WithACounter { my $next_count = 1; field $count = $next_count++; }

    But it doesn't say that any other kind of code can be present there. For example, maybe I'd like to do this:

    class WithACounter { my $next_count = 1; if (last_one_was_bad()) { delete_last_one(); $next_count--; } field $count = $next_count++; }

    Would that be permitted?

    Also: it looks like the my variables there are essentially "class static" members — so called in other languages e.g. C#. Is that an accurate characterization?

    Today's latest and greatest software contains tomorrow's zero day exploits.
bignum and parenthesis
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 03, 2023 at 13:49
    for __ in $$; do perl -Mbignum -le 'print 7 ** 127 % 524287 ' perl -Mbignum -le 'print ( 7 ** 127 ) % ( 524287 )' echo ' ( 7 ^ 127 ) % 524287 ' | bc done | gcat -b 1 102010 2 212545092456801670844330383105896224333193816736399849985499 +757869483902203328714236393937418376186556719543 3 102010
    How come adding parenthesis screws up the calculation here ? The middle one simply outputted 7 ** 127 without modulating it down The equation being tested is Mersenne Primes ( M3 ** M7 ) mod M19 Thanks.
    perl -V Summary of my perl5 (revision 5 version 36 subversion 1) configuration +: Platform: osname=darwin osvers=22.4.0 archname=darwin-thread-multi-2level uname='darwin ventura-arm64.local 22.4.0 darwin kernel version 22. +4.0: mon mar 6 20:55:35 pst 2023; root:xnu-8796.101.5~3release_arm64_ +vmapple arm64 '
Regexp::Common and "multidimensional hash lookup disabled" (v5.36+)
3 direct replies — Read more / Contribute
by ibm1620
on Jul 01, 2023 at 18:37
    Dear Monks,

    I need to extract substrings delimited by balanced parentheses, and I installed Regexp::Common to see what it could do. Here is a test program that embeds an example from the doc (https://metacpan.org/pod/Regexp::Common).

    #!/usr/bin/env perl use v5.36; use Regexp::Common; while (<>) { /$RE{num}{real}/ and print q{a number}; /$RE{quoted}/ and print q{a ['"`] quoted string}; m[$RE{delimited}{-delim=>'/'}] and print q{a /.../ sequence}; /$RE{balanced}{-parens=>'()'}/ and print q{balanced parentheses}; /$RE{profanity}/ and print q{a #*@%-ing word}; }
    Unfortunately, it won't compile:
    Multidimensional hash lookup is disabled at /Users/chap/private/perl/r +egcommon line 8, near "'/'}"
    It seems that, at some point, it was permissible to write $foo{$bar, $frog}, which was understood by Perl to mean $foo{"$bar$;$frog"}, but this was later disabled (perl 5.33?). And I assume that {-delim=>'/'} is what's triggering the error, with '=>' being a fat comma.

    Is Regexp::Common out of date? None of the 28 open issues seems to address this condition. Is there a way to make it work under v5.36 and beyond? Is there a successor to Regexp::Common?

    (Incidentally, it seems from searching for "perl multidimensional hash" that most people take this to mean simply chaining keys, a la $thing{$x}{$y}{$z}, which of course is alive and well, as opposed to forming a "composite key" as in $thing{$x, $y, $z}).

    Update 1: replaced literals with variables in examples of multidimensional hash lookups, per jwkrahn's comment below.

Meditations
EyeBall stumps BodBall
3 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Jul 06, 2023 at 20:18

    However, I will not call die. I find it frustrating when modules die.

    -- Bod in Re^6: STDERR in Test Results

    While I doubt Bod, hailing from (working-class) Coventry UK, would be permitted to enter the hallowed Long Room at Lords to hurl abuse at the Australian cricket team during the Ashes test match last weekend, I'm sure he won't be stumped by this meditation's title ... unlike monks from non-cricket-playing nations, doubtless unfamiliar with Bazball :).

    Bodball, you may recall I once scolded you for asking "what should I test?" long after you'd released your module. I similarly urge you to get into the habit of thinking long and hard about your module's error handling well before you release it, and for the same reasons. Like TDD, it's crucial to perform this error-handling analysis early because doing so will likely change your module's interface.

    Further to the excellent general advice you've already recieved from afoken, I'm interested to learn more about the errors you commonly encounter in practice when using your Business::Stripe::Webhook module. I also urge you to add an expanded "Error Handling" section to your module's documentation.

    General Error Handling Advice

    Don't fail silently. Failure is inevitable; failing to report failures is inexcusable. Failing silently causes the following problems:

    • Users wonder whether something has gone wrong. ("Why did my order not go through?")
    • Customer support wonders what caused a problem. ("The log file gave no indication of a problem")

    Embrace your software's fallibility. Assume that humans will make mistakes using your software. Try to minimize ways for people to misuse your software, but assume that you can't completely eliminate misuse. Therefore, plan error messages as you design software.

    -- General error handling advice from Google Error Messages course

    Programming Tips

    What should a function do if it cannot perform its allocated task?

    • return a value indicating failure
    • throw an exception
    • terminate the program

    Return failure when:

    • an error is normal and expected (e.g. opening a file)
    • an immediate caller can reasonably be expected to handle the failure

    Throw an exception when:

    • an error is so rare that the programmer is likely to forget to check for it
    • an error cannot be handled by the immediate caller
    • new kinds of errors are added in lower modules that higher level modules were not written to cope with
    • no suitable return path for error codes is available (e.g. semipredicate problem)
    • return path of a function is made uglier by the need to return an error indicator
    • the function that found the error was a callback
    • an error requires an "undo" action (unlike RAII say)

    This is not a black and white issue. Experience and good taste are required.

    Business::Stripe::Webhook Error Handling

    Though unfamiliar with your Business::Stripe::Webhook domain, I briefly browsed your module's documentation. Good to see you've already written a short "Errors and Warnings" section in its documentation; I suggest you improve and expand this section for the next release.

    AFAICT, your basic error handling strategy is for your methods to set the error property, for example:

    $vars{'error'} = 'Missing payload data'
    with the module user expected to check this error property after calling each method. Is that right?

    I think a clear statement of your overall error-handling strategy, combined with a couple of real-world examples of handling common errors you've experienced when using your module, would be invaluable to your users ... and may cause you to tweak your module's error-handling code and interface ... which is why this step is ideally performed well before release. :)

    See Also

    Updated: minor changes to wording were made shortly after posting.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-07-08 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?