Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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
poll ideas quest 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
5 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
The Perl and Raku Conference 2021 online
on Jun 08, 2021 at 02:55
0 replies by Discipulus
    Hello folks!

    today starts the The Perl and Raku Conference, Conference in the Cloud, at 11:30 New York time (16:30 GMT).

    You can see how-to-attend-this-conference and the whole scheduling.

    Profit it!

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Perl questionaire by Gobby
on Jun 02, 2021 at 03:54
6 replies by Tux

    A shared Vision of Perl

    Hello!

    Welcome to the survey on a shared vision of Perl!

    Gobby is an innovative, Perl-based, survey tool. We're committed to the future of the Perl ecosystem and people that make up these communities.

    We're looking for support in the development of Gobby as a Perl product. Please drop us a line to info@gobby.io if you like our approach to surveys and would like to be part of Gobby's future.

    Best wishes,

    Gary Beckwith
    Founder of Gobby


    Enjoy, Have FUN! H.Merijn
Supplications
The "%" operator and its documentation.
1 direct reply — Read more / Contribute
by syphilis
on Jun 13, 2021 at 21:40
    Hi,

    UPDATE: I've now filed a bug report about this.

    I've been chewing on this over the last couple of days, and it doesn't look right to me.
    It's an issue that arises only when NV-precision is greater than IV-precision.
    So, if ivsize is 8 bytes, then in order to experience the issue, you'll generally need to use a quadmath build (nvtype of __float28, NV-precision of 113 bits).
    With such a perl, I get:
    C:\_32>perl -wle "$m = (2**113) - 1; $n = 2; print $m % $n;" 0
    In contrast, POSIX::fmod returns "1" for the same operation.
    C:\_32>perl -MPOSIX -wle "$m = (2**113) - 1; $n = 2; print fmod($m, $n +);" 1
    Here's the section of perlop documentation that I'm looking at:
    Binary "%" is the modulo operator, which computes the division remaind +er of its first argument with respect to its second argument. Given integ +er operands $m and $n: If $n is positive, then "$m % $n" is $m minus the largest multiple of $n less than or equal to $m. If $n is negative, th +en "$m % $n" is $m minus the smallest multiple of $n that is not less tha +n $m (that is, the result will be less than or equal to zero). If the operands $m and $n are floating point values and the absolute value of $n (that is "abs($n)") is less than "(UV_MAX + 1)", only the integer portion of $m and $n will be used in the operation (Note: here "UV_MAX +" means the maximum of the unsigned integer type). If the absolute value of the right operand ("abs($n)") is greater than or equal to "(UV_MAX + 1)", "%" computes the floating-point remainder $r in the equation "($r = $m - $i*$n)" where $i is a certain integer that makes +$r have the same sign as the right operand $n (not as the left operand $m like C function "fmod()") and the absolute value less than that of $n. Note that when "use integer" is in scope, "%" gives you direct access +to the modulo operator as implemented by your C compiler. This operator i +s not as well defined for negative operands, but it will execute faster.
    AFAICT, the parts of that documentation that are pertinent to my given example are:
    If $n is positive, then "$m % $n" is $m minus the largest multiple of +$n less than or equal to $m. .... If the operands $m and $n are floating point values and the absolute v +alue of $n (that is "abs($n)") is less than "(UV_MAX + 1)", only the integer portion of $m and $n will be used in the operation (Note: here "UV_MAX +" means the maximum of the unsigned integer type)
    And to me that implies that the correct calculation for the given example is to do:
    C:\_32>perl -wle "$r = 10384593717069655257060992658440191.0 - (519229 +6858534827628530496329220095.0 * 2); print $r;" 1
    This agrees with the value produced by POSIX::fmod(), but disagrees with the value produced by the "%" operator.
    Do we agree that perl is buggy here ?

    If you have a perl with ivsize of 4, you can also demonstrate the same issue.
    With ivsize of 4, NV-precision of 113 bits:
    C:\_32>perl -wle "$m = (2**113) - 1; $n = 2; print $m % $n;" 0 C:\_32>perl -MPOSIX -wle "$m = (2**113) - 1; $n = 2; print fmod($m, $n +);" 1
    With ivsize of 4, NV-precision of 64 bits (long double):
    C:\>perl -wle "$m = (2**64) - 1; $n = 2; print $m % $n;" 0 C:\>perl -MPOSIX -wle "$m = (2**64) - 1; $n = 2; print fmod($m, $n);" 1
    And now to really muddy the waters !! One might be expecting the trend to continue when ivsize is 4, and NV-precision is 53-bits .... but not so:
    C:\_32>perl -wle "$m = (2**53) - 1; $n = 2; print $m % $n;" 1 C:\_32>perl -MPOSIX -wle "$m = (2**53) - 1; $n = 2; print fmod($m, $n) +;" 1
    This time the "%" operator decides to act in accordance with (my reading of) the perlop documentation.

    Cheers,
    Rob
When not to use taint mode
8 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?

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
1 direct reply — Read more / Contribute
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,

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

Meditations
Organizational Culture (Part I): Introduction
3 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Jun 11, 2021 at 07:58

    The recent turmoil in Perl's organizational culture, discussed recently here at Perl Monks in:

    left me feeling sad. Sadder after reading of the Australian Defence Force's long-drawn-out battles with cultural change: because it made me realise that organizational cultural problems are dauntingly difficult - and often prohibitively expensive - to put right.

    For therapy, I've decided to follow up my nine-part series on Agile processes in organizations with a new (ten-part :-) series of articles exploring the perplexing multi-disciplinary topic of Organizational Culture. There's certainly no shortage of material, with a mind-boggling number and variety of disciplines in play, such as:

    Please feel free to mention other disciplines I've overlooked or that you'd like to see discussed.

    A possible breakdown by topic is:

    • Broad Overview of Organizational Culture
    • Meta Process: that is, a process to build a process to effectively change Organizational Culture
    • Culture variation in different countries
    • Software Industry Culture
    • Open Source Software Culture
    • Perl Culture
    • Perl Monks Culture! :)
    • Space/Aircraft Industry Culture. As a space nut, I doubt I'll be able to restrain myself from scrutinizing the impact of organizational culture on the Space Shuttle Challenger and Columbia disasters.
    Again, feel free to suggest other topics you'd like to see discussed.

    Please note that I'm just an interested layman on all these topics, so please correct me when I veer off course. I also welcome your feedback and opinion, along with insights, anecdotes and any useful citations you may know of.

    To kick off this series, given that I've just finished reading Sapiens, I thought it'd be fun to speculate on how our early evolutionary history helps explain some of the peculiar and counter-productive behaviour we witness today.

    PreHistory

    Around 2.5 million years ago, an unremarkable new species appeared in Africa. Now, I doubt these early humans, enduring their daily battle for survival along with many other species, had any inkling back then that they would one day walk on the moon, split the atom, map the genome, calculate the age of the universe ... and compose Perl programs, obfus and poetry.

    How on earth did this unremarkable and physically weak new species win this brutal evolutionary war? Sapiens revealed the (surprising to me) secret:

    A green monkey can yell to its comrades, "Careful! A lion!". But a modern human can tell her friends that this morning, near the bend in the river, she saw a lion tracking a herd of bison. She can then describe the exact location, including the different paths leading to the area. With this information, the members of her band can put their heads together and discuss whether they should approach the river, chase away the lion, and hunt the bison.

    Homo sapiens is primarily a social animal. Social cooperation is our key for survival and reproduction. It is not enough for individual men and women to know the whereabouts of lion and bison. It's much more important for them to know who in their band hates whom, who is sleeping with whom, who is honest, and who is a cheat. ... The most important information that needed to be conveyed was about humans, not lions and bison. Our language evolved as a way of gossiping.

    Do you think that history professors chat about the reasons for the First World War when they meet for lunch, or that nuclear physicists spend their coffee breaks at scientific conferences talking about quarks? Sometimes. But more often, they gossip about the professor who caught her husband cheating, or the quarrel between the head of the department and the dean, or the rumours that a colleague used his research funds to buy a Lexus.

    Only Homo sapiens can speak about things that don't really exist. You could never convince a monkey to give you a banana by promising him limitless bananas after death in monkey heaven. But why is it so important? Fiction has enabled us not merely to imagine things, but to do so collectively. We can weave common myths. Such myths give Sapiens the unprecedented ability to cooperate flexibly in large numbers.

    Ants and bees can also work together in huge numbers, but they do so in a very rigid manner and only with close relatives. Sapiens can cooperate in extremely flexible ways with countless numbers of strangers. That's why Sapiens rule the world, whereas ants eat our leftovers and chimps are locked up in zoos. (Update: so far researchers have failed to locate lawyer bees; bees don't need lawyers because there is no danger that they might forget or violate the hive constitution).

    Myths and fictions accustomed people, nearly from the moment of birth, to think in certain ways, to behave in accordance with certain standards, to want certain things, and to observe certain rules. They thereby created artificial instincts that enabled millions of strangers to cooperate effectively. This network of artificial instincts is called culture.

    The theory of evolution tells us that instincts, drives and emotions evolve in the sole interest of survival and reproduction ... yet when some of these evolutionary pressures abruptly disappear (due to sudden changes in human culture), these hard-won instincts do not instantly disappear with them ... which explains why today young men drive recklessly and fight in pubs. They are simply following ancient genetic impulses that, though counter productive today, made perfect sense 70,000 years ago, where a young hunter who risked his life chasing a mammoth outshone all his competitors to win the affections of the local beauty. Sadly, those same successful macho genes today give us a mouthful on Perl mailing lists, IRC and Twitter.

    With their brain growing (to keep track of the thousands of connections, deceits and subterfuge required for superior gossiping) and their hips narrowing (to facilitate walking upright), evolution favoured early births ... leading to helpless babies ... requiring a tribe to raise them ... favouring those with strong social abilities. Being born immature and with a big brain further allowed humans to be taught more flexibly than any other species -- which explains why we witness today the appalling spectacle of impressionable youngsters being effortlessly led to love Python and hate Perl.

    PM References

    Updated: Make Homo sapiens stand out from surrounding text, and with the species name (sapiens) in all lower case, a convention used by biologists, such as erix. 13-June: added bee lawyer joke to quoted Sapiens passage.

Cool Uses for Perl
3D printing with out slicers and safety nets
No replies — Read more | Post response
by cavac
on Jun 09, 2021 at 12:21

    As some of you might know, i'm running a simulated space agency for fun and non-profit.

    A couple of years ago i came across something called crushable aluminium honeycomb for things like one-time-use super lightweight shock absorbers. ESA also has some version of special aluminium foam for the same purpose. Those super rich engineering departments over at ESA and NASA really have all the coolest toys, though.

    I don't have the metal working tools to replicate that (or a furnace or blocks of aluminium, for that matter). But i do have a couple of 3D printers and i know Perl. That's pretty much the same thing, isn't it?

    Looking at the requirements of how a 3D printed crushable PLA structure could work, it was pretty clear from the start that using a modeling program like OpenSCAD and a slicer software wouldn't work. My plan is to print a hard structure filled with lots of very thin PLA strands that would break under load, therefore absorbing energy. The slicer would either print those strand too thick or would remove them entirely.

    The only option i could see that would generate the results i want was to generate the printer commands myself. After a lot of on-and-off tinkering, i still don't have a working crushable structure, but i decided to post my printer test code now, so you all have a chance to play around with it if you want.

    A word of warning! The code is printer specific (i'm using a modified Creality Ender 5 Pro), so you will have to adapt at least some settings. Most 3D printers are also very dumb and will try to do whatever you tell them to do - most times "no matter what the consequences are". If you tell your printer "move the head 10 meters to the left and then set the extruder temperature to the surface temperature of the sun" it will happily crash the head and then try to burn your house down. I've named my codebase "Project Arcturus", if you are a Stargate Atlantis fan, you'll know why ;-)

    This code will generate my default "test object". Let's dive into it.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
New Obfuscated Code
A twisty little maze of ampersands, all different
1 direct reply — Read more / Contribute
by haj
on Jun 08, 2021 at 18:54
    The following code prints a 0, a 1, a 2, and an empty line. But which is which?
    use 5.020; sub one { 1 } sub two { 2 } say one&two ; say &one&two ; say &one&&&two ; say &&&one&&&two;

    It is not that difficult to figure out, it was a accidental discovery while messing around with syntax highlighting. For the friends of JAPH, here's one with five consecutive ampersands:

    use 5.020; sub s { say }; $_ = 'Jusst another Perl hacker'; s&s&&&&&s
PerlMonks Discussions
Markdown is now supported for comments, experimentally
3 direct replies — Read more / Contribute
by jdporter
on Jun 09, 2021 at 15:15

    Due to "popular demand", PerlMonks now supports Markdown formatting for writeups. Note: Initially, Markdown is only supported for comments (aka notes). If everyone likes it, we will extend the capability to root-level posts as well (SOPW posts, etc.)

    Some relevant past discussions:

    Sorry it took me a minute to implement this feature. :-D

    To enable the use of Markdown in your comments, go to your User Settings and change the "Format writeups as:" selection from 'conventional' to 'markdown'.

    Be aware that this is a global setting. You can't select the format at the time you submit the writeup.

    When you are looking at a writeup entry box (textarea), you will see a short note immediately above it indicating which markup you can use.

    This change was actually relatively simple to implement, since modules for converting markdown to HTML already existed.
    I would like to know if there is any demand for any other Lightweight markup languages.
    For example, we could add support for Textile or some flavor of wiki text.

    I reckon we are the only monastery ever to have a dungeon staffed with 16,000 zombies.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-06-15 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (73 votes). Check out past polls.

    Notices?