Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

The Monastery Gates

( [id://131]=superdoc: print w/replies, xml ) Need Help??

If you're new here please read PerlMonks FAQ
and Create a new user.

Quests
Wall of Larry Quest
Starts at: Feb 26, 2024 at 05:00
Ends at: Dec 31, 2024 at 04:59
Current Status: Active
2 replies by jdporter

    By now you've all seen The St. Larry Wall Shrine. Well, it could use a fresh coat of gold leaf and shellac. Therefore, we are soliciting Larry-related items to be placed on the shrine. Links to offsite content are good; or if you have small bits of content, such as quotes, you'd like to contribute, that's fine too. Please reply to this Quest with your humble offerings. Thank you! And may St. Larry bless your codings and your debuggings.

poll ideas quest 2024
Starts at: Jan 01, 2024 at 00:00
Ends at: Dec 31, 2024 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.

Monk Quips Quest
Starts at: May 01, 2023 at 08:00
Ends at: Apr 30, 2024 at 07:59
Current Status: Active
9 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.

    .

Perl News
Registration for The Perl and Raku Conference 2024 is open!
on Mar 16, 2024 at 00:59
0 replies by talexb

    The Perl and Raku Conference (formerly known as YAPC::NA) is going strong!

    This year, we are celebrating 25 years, our silver anniversary, in the Silver State, Nevada! The main conference will be in Las Vegas on June 25-27, but there will be hackathons and possibly classes on the day before and the day after the conference (June 24th and 28th), so please consider joining us for the whole week!

    The backbone of this conference has always been our tracks of "traditional" talks by community members and what we have come to call the "Hallway Track", the informal exchange of ideas and camaraderie that sparks new projects and fuels collaboration.

    This year, we are pleased also to host the presentation of Papers and Posters accepted by the Science Perl Journal!

    Go now to https://tprc.us/ to check out what is planned and to book a room (see link to Alexis Park Resort under "Location"). Rooms start at only $75 per night, so it’s worth booking early!

    The best way to register for the conference is here.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Houston Perl Mongers March Meeting #1
on Mar 12, 2024 at 16:25
0 replies by oodler
    Houston Perl Mongers presents:
    Title: Introducing Intellexer::API
    When: Thur March 14th at 6:00-8:00 PM CT (+6 UTC)
    Where: (virtual, see below):
    What: Josh Day (HAX) will discuss his new CPAN module Intellexer::API
    https://us02web.zoom.us/j/920069702
    Meeting ID: 920 069 702
    Password can be found by running this statement or reading the comment. perl -e 'print +(0b1000100).((3<<2)*10).(010)."\n"' # 681208
    
    We are starting a second meeting on the 4th Wednesdays of each month via our Discord server. Details shall be posted in a couple of weeks. We also have a Facebook page, just search for "Houston Perl Mongers". Open access.
Supplications
Lexical variable not available
3 direct replies — Read more / Contribute
by choroba
on Mar 18, 2024 at 17:06
    Copied from one of the Perl Discords:

    By user "timka7060":

    Who can figure this out. I narrowed down my issue in some other code to this simple use case:
    # Can print $v only once!!! # Second call returns undef. # Some coderef optimization??? # Lexical variable goes undef on second call. # sub { my $v = 111; eval q( eval 'print $v, "\n"'; # 111 eval 'print $v, "\n"'; # undef ); }->();

    User "tyrrminal" replies with:

    If you enable warnings, you see a line Variable "$v" is not available at (eval 3) line 1. Googling that led me to a stack overflow response which seems to relate to your case (2nd answer, starting with See perldiag)

    timka7060's reaction:

    So why does the first eval output 111?
    (I'd figure either both lines should be 111 or both undef.)
    Btw, prior to 5.10, both lines would output 111: https://perlbanjo.com/b28dce8db2
    This is a simple fix, but only for a single variable: https://perlbanjo.com/13dbb8d48d

    My observation:

    sub { my $v = 111; eval q( eval 'print $v, "A\n"'; eval 'print $v, "B\n"'; print $v, "C\n"; ); }->();
    Now, none of either A or B sees $v, but C (obviously) does.

    What's going on here?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Calling a sub without enclosing its argument inside brackets
2 direct replies — Read more / Contribute
by syphilis
on Mar 18, 2024 at 00:05
    Hi,

    The demo:
    use strict; use warnings; use Math::BigInt; # The following line of code will die with: # Can't locate object method "palt" via package "Math::BigInt" at try. +pl line 7. # palt Math::BigInt->new(123456); # But this next rendition is fine, and works as expected: palt(Math::BigInt->new(123456)); sub palt { my $arg= shift; print "$arg\n"; } __END__ Outputs: 123456
    Is there some technique that will allow me to make that (failing) call work - without having to place that argument in brackets ?

    Cheers,
    Rob
The Y2K 2038 problem
1 direct reply — Read more / Contribute
by harangzsolt33
on Mar 17, 2024 at 21:05
CRC-16/X25 problem
3 direct replies — Read more / Contribute
by bonzi
on Mar 16, 2024 at 15:25

    I need to calculate CRC-16/X25 checksum/digest in order to communicate with some instrument. I am using Digest::CRC module and https://crccalc.com/ site for both the source of appropriate parameters and to check the result. (The examples in the instrument manual agree with results on csccalc.com.) However, I cannot seem to get correct results. Here is a snippet of may code:

    use Digest::CRC; my ($crc, $input, $width, $init, $xorout, $refout, $poly, $refin, $con +t, $digest, $ctx); $width = 16; $init = 0xffff; $xorout = 0xffff; $refout = 1; $poly = 0x1021; $refin = 1; $cont = 0; # ??? $input = 0xaabbccdd; $ctx = Digest::CRC->new(width=>$width, init=>$init, xorout=>$xorout, refout=>$refout, poly=>$poly, refin=>$refin, cont=>$cont); $ctx->add($input); $digest = $ctx->hexdigest; say $digest;
    I am either interpreting the parameters incorrectly, on missunderstand the arcana of pack/unpack functions and the need for them, or something else entirely. A bit of enlightenment would be appreciated.
Most Significant Set Bit
8 direct replies — Read more / Contribute
by coldr3ality
on Mar 15, 2024 at 09:19
    Blessed Monks, I humbly prithee guidance bestow. I'm looking to benchmark for a variant of the binary search algorithm, but before I begin I'm trying to bake it down to the most efficient Perl code I possibly can. I'm looking for the most efficient way to find the Most Significant Set Bit of a given integer value. I am unaware of a Perl function that does this. I have almost no experience in C, but I read that GCC does have an algorithm for this. Up to now, I have been using the following code to find the most significant set bit of a given 64-bit integer. I did my best to format it legibly here; though it looks like puke, it's a single statement. Is there a better performing solution?
    $m is assigned the most significant set bit of 64-bit integer $z, for +the cost of 6 ANDs and 6 truth tests. my $m=-4294967296&$z? -281474976710656&$z? -72057594037927936&$z? -1152921504606846976&$z? -4611686018427387904&$z? -9223372036854775 +808&$z? 4611686018427387904: 2305843009213693952 : -2305843009213693952&$z? 1152921504606846976: 576460752303423488 : -288230376151711744&$z? -576460752303423488&$z? 288230376151711744: 144115188075855872 : -144115188075855872&$z? 72057594037927936: 36028797018963968 : -4503599627370496&$z? -18014398509481984&$z? -36028797018963968& +$z? 18014398509481984: 9007199254740992 : -9007199254740992&$z? 4503599627370496: 2251799813685248 : -1125899906842624&$z? -2251799813685248&$z? 1125899906842624: 562949953421312 : -562949953421312&$z? 281474976710656: 140737488355328 : -1099511627776&$z? -17592186044416&$z? -70368744177664&$z? -1407374 +88355328&$z? 70368744177664: 35184372088832 : -35184372088832&$z? 17592186044416: 8796093022208 : -4398046511104&$z? -8796093022208&$z? 4398046511104: 2199023255552 : -2199023255552&$z? 1099511627776: 549755813888 : -68719476736&$z? -274877906944&$z? -549755813888&$z? 274877906944: 137438953472 : -137438953472&$z? 68719476736: 34359738368 : -17179869184&$z? -34359738368&$z? 17179869184: 8589934592 : -8589934592&$z? 4294967296: 2147483648 : -65536&$z? -16777216&$z? -268435456&$z? -1073741824&$z? -2147483648& +$z? 1073741824: 536870912 : -536870912&$z? 268435456: 134217728 : -67108864&$z? -134217728&$z? 67108864: 33554432 : -33554432&$z? 16777216: 8388608 : -1048576&$z? -4194304&$z? -8388608&$z? 4194304: 2097152 : -2097152&$z? 1048576: 524288 : -262144&$z? -524288&$z? 262144: 131072 : -131072&$z? 65536: 32768 : -256&$z? -4096&$z? -16384&$z? -32768&$z? 16384: 8192 : -8192&$z? 4096: 2048 : -1024&$z? -2048&$z? 1024: 512 : -512&$z? 256: 128 : -16&$z? -64&$z? -128&$z? 64: 32 : -32&$z? 16: 8 : -4&$z? -8&$z? 4: 2 : 2 ;
I wrote a very ugly piece of code, can someone help me correct it?
1 direct reply — Read more / Contribute
by glwa
on Mar 14, 2024 at 15:09
    I am not very experienced with perl, but I know enough that this looks pretty bad
    $dbh->begin_work; my $href = $dbh->selectall_hashref("SELECT * FROM data WHERE ToScan IS + NULL AND title IS NOT NULL limit 1 FOR UPDATE SKIP LOCKED", "someid" +); foreach my $tmp (keys %$href) { $ID=$href->{$tmp}->{'id'}; $title=$href->{$tmp}->{'title'}; $channel=$tmp; } my $rsth=$dbh->prepare("UPDATE data SET lock=1 WHERE id='$ID'"); $rsth +->execute() || die $rsth->errstr; $dbh->commit;
    is there any cleaner way of doing this? I need to "...FOR UPDATE" then get the ID of selected row to set a lock on it. My code works but is very ugly. Thank you
Problem combining hashes
3 direct replies — Read more / Contribute
by jh
on Mar 14, 2024 at 12:20
    Hello fellow monks, I've been Perl'ing for a long time and maybe I just haven't consumed sufficient caffeine today, but... I am at a loss. I have two hashes:
    %A = (a => 1, b => 2, c => 3); %Z = (z => 9, y => 8, x => 7);
    and I want to populate an array with all the keys in either. It works great if I do it as two steps:
    %combined = (%A, %Z); @all_keys = keys %combined;
    No problem. But I want to do it in one step:
    @all_keys = keys %{{ %A, %Z }};
    that works fine but it's a little extra (and I know my code is soon going to inflicted on a junior dev, so...) and anyway it seems like I ought to be able to do something simpler. So where it blows up is when I try to do:
    @all_keys = keys(%A, %Z);
    I get

    Experimental keys on scalar is now forbidden at - line 3.
    Type of arg 1 to keys must be hash or array (not list) at - line 3, near "%Z)"
    Execution of - aborted due to compilation errors.

    There isn't a scalar in sight, the type of arg1 is definitely a hash, and I am trying to figure out what is going on. I would have expected this just to function as a hash overlay, with the results passed to keys(), wham, bam, eat some jam. OK, maybe keys() is doing something fancy to its args? Functions like pop() know that the first arg is a real array, so maybe keys() is treating this as two args and not doing the overlay (and I've never passed more than one arg to keys()---why would I?---but my various attempts to fool the compiler clarify that the overlay should happen don't work either:
    @all_keys = keys((%A, %Z)); @all_keys = keys(%temp::var = (%A, %Z)); @all_keys = keys(my %temp = (%A, %Z)); @all_keys = keys(do { %{{%A, %Z}} });
    ...not that the last one is "cleaner" that the version above that works

    All generate the same error as above, and in fact none but the first work even if I take out the overlay part:
    @all_keys = keys(%temp::var = (%A)); @all_keys = keys(my %temp = (%A)); @all_keys = keys(do { %{{%A}} });
    What is going on?
Reason for this discrepancy with scalar?
3 direct replies — Read more / Contribute
by kikuchiyo
on Mar 13, 2024 at 16:31

    Consider the following program:

    perl -MDevel::Peek -le 'my @nonempty = (1); my @empty = (); print Dump +(scalar @nonempty); print Dump(scalar @empty)' SV = IV(0x563dfe2d16f0) at 0x563dfe2d1700 REFCNT = 1 FLAGS = (TEMP,IOK,pIOK) IV = 1 SV = PVNV(0x563dfe2d0200) at 0x563dfe2ce410 REFCNT = 2147483647 FLAGS = (PADTMP,IOK,NOK,POK,READONLY,PROTECT,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x7fb0f957d3c2 "0" CUR = 1 LEN = 0

    Which is to say, scalar returns a PV if the array is empty, and an IV if it is not. This can be a problem, because most serializers, including JSON modules, will encode the PV as "0" and the IV as 1, which will cause a problem if the consumer of the resulting JSON expects strict type conformance.

    Is there a logical reason for this discrepancy?

    (Yes, I know that I could just do 0+scalar @array - my point is that that shouldn't be necessary.)

CGI.pm ignore URL GET query string parameters
1 direct reply — Read more / Contribute
by Danny
on Mar 13, 2024 at 15:13
    With CGI.pm you can avoid using query string parameters listed in the URL with a GET request by checking $cgi->request_method() eq 'POST', but is there a way to keep those GET parameters from populating $cgi->param(), other than hacking the module?
Meditations
Changes in MooX::Role::Parameterized
No replies — Read more | Post response
by choroba
on Mar 17, 2024 at 16:12

    What is it good for?

    If you’ve never worked with MooX::Role::Parameterized or MooseX::Role::Parameterized, you might wonder what is a parameterized role at all?

    Roles are used when you need to share behaviour among several classes that don’t have to be related by inheritance. Normally, a role just adds a bunch of methods to the class that consumes it (there’s more, you can for example specify which other methods the role expects to already exist).

    A parameterized role makes it possible to provide parameters for the consumed role. This way, you can adjust the behaviour for each consuming class.

    The old syntax

    The standard syntax to apply a role to a class before version 0.100 of the module was to use the apply class method:

    # My/Role.pm package My::Role; use Moo::Role; use MooX::Role::Parameterized; role { my ($params, $mop) = @_; $mop->has($params->{name} => is => $params->{is}); }

    # My/Obj.pm package My::Obj; use Moo; use My::Role; 'My::Role'->apply({ name => 'size', is => 'ro', });

    If we now created an object $o using my $o = 'My::Obj'->new(size => 2), we could get the value of the attribute size using the $o->size getter: the role created a new read-only attribute size for us.

    The old experimental syntax

    What I didn’t like about applying a role to a class the old standard way was it wasn’t declarative. You could easily overlook it as a block of code happening at runtime, while the meaning of the code was This is how a role is consumed. Therefore, I used the alternative experimental syntax:

    package My::Obj; use Moo; use MooX::Role::Parameterized::With 'My::Role' => { name => 'size', is => 'ro', };

    It's part of a use clause, so it’s clear that it’s happening at compile time.

    The new syntax

    I promoted one of my side-jobs to a full-time job recently. They gave me a new computer where I had to install all my code base to start working on it 8 hours a day instead of a couple a month.

    Imagine my surprise when the code stopped with an error:

    Can't locate object method "size" via package "My::Obj" at ./run.pl line 37.

    Line 37 was where I called $o->size!

    When installing the dependencies for my code, the most recent version of MooX::Role::Parameterized was installed from CPAN (0.501). The experimental syntax is no longer documented and as I found out, doesn’t work anymore.

    The old non-experimental syntax still works, but there’s a new syntax, too. It uses the with keyword that looks like the one that can be used to consume a Moo::Role, but if we first use MooX::Role::Parameterized::With, it can also accept parameters for the role application.

    package My::Obj; use Moo; use MooX::Role::Parameterized::With; with 'My::Role' => { name => 'size', is => 'ro', };

    Moreover, we should change the definition of the role, too. Parameters should be predeclared using the parameter keyword (similarly to MooseX::Role::Parameterized), and they can be then accessed via getters instead of peeking inside a parameter hash reference.

    package My::Role; use Moo::Role; use MooX::Role::Parameterized; parameter name => (is => 'ro'); parameter is => (is => 'ro'); role { my ($params, $mop) = @_; $mop->has($params->name => is => $params->is); }

    Note: Published to my blog, too.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
PerlMonks Discussions
New Feature: What Links Here
1 direct reply — Read more / Contribute
by jdporter
on Mar 18, 2024 at 14:15

    Alrighty, folks! I've got another steaming-new feature for you: What Links Here

    There is a new nodelet you can enable, if you are interested in this feature. Go to your Nodelet Settings and find "What Links Here" somewhere near the top of the list.
    Then, whatever node you're on, this nodelet will show what other nodes link to the current node.

    It caps out at 100, so for some nodes, such as PerlMonks FAQ, it will just show "too many results".

    The database table behind this feature is not automatically maintained (yet), so I'll need some volunteers from pmdev to occasionally visit Update Userspace Links. Doing so will cause a delta update to the table.

    I was inspired by this old quote from Rob Malda:

    The thing that I always thought was the most interesting in Xanadu is the idea that links are bi-directional. And the Everything Engine was designed around that.

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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-19 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found