If you've discovered something amazing about Perl that you just need to share with everyone,
this is the right place.
This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)
Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").
It has taken me a long time to talk about this in public, but i think it's finally time to tell you: I am on the autistic spectrum.
A lot has been written about the subject, so i wont bore you with too much detail. Autism is a sliding scale, with many a variation on how this
can affect an individual.
For me, i have trouble keeping a conversation going both ways (i tend to talk non-stop if i get any chance). For some strange reason, this is much easier in writing than it is in person. When i write (and read), i usually can take my time, and analyze what the other people are saying and slowly formulate my answers. In person, i can still do it (depending on the subject), but it is very stressful. I also have trouble understanding non-verbal cues, can't remember faces very well and stuff. To others, I also tend to have a very dark humor; for everything else i tend to apply logic. But mostly, for me it's a day-to-day struggle to appear somewhat normal in public and somehow muddle through the day without completely loosing my mind or doing something incredibly stupid. There are other things as well, but these are for another time, perhaps. But basically, think "high-functioning autism", i can hide my traits by many learned ways of coping with stuff, but this requires a lot of active concentration and it's quite stressful and exhausting to do (if you ever meet me in person, you'll probably notice my various social "skills" dropping fast whenever i am tired).
The reason why i'm writing this is simple: PerlMonks has been a haven of calmness and sanity to me over many, many years. It gives me a chance to learn from and give back to others. Sometimes, i only lurk here without writing for months, then there are times when i'm ready to take on quest after quest to try and help out in SoPW. The discussions here are generally held in a calm and logical fashion that let me participate in my own way and at my own speed. And for this, i am eternally grateful to all of you.
Thank you from the bottom of my heart!
Edit: Ask me questions. I'll answer them if i can.
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
I needed to lock a SQLite(3) database in order to test whether my code for writing to it fails gracefully, or my code for reading circumvents the lock by, lamely, copying it to a new file.
After some help from Discipulus' google-fu I have ended using this for locking the DB: PRAGMA locking_mode = EXCLUSIVE; BEGIN EXCLUSIVE; . (unfortunately unlocking it with COMMIT; does not work for me and I unlock it with a disconnect).
The test file will use a fork() whose child will open the db and lock it as above and sleep for some time before disconnecting (thus unlocking it). The parent will try to open the DB and hopefully be able to detect if locked or not.
A week or so ago there was this big volcano eruption in Tonga that created Tsunamis and such. Terrible stuff.
I knew that big events like this can create pressure waves in the air that can travel across the globe. I just recently installed an air pressure sensor, a BME280 to my radio network. I had my doubts if such a cheap sensor could actually detect such faint changes in air pressure. Well, it's more sensitive than i thought
I joined PerlMonks 20 years ago and never looked back. At that time I used Perl for the care and feeding of one of the largest relational databases in the Department of Defense, but because it was within the Intelligence Community there was little I could say about it. The use of Perl earned me the nickname "Mr. Magic", but the magic was in Perl, not in me. I took my signature line from an article in Datamation magazine in the 1980's, but it was over a decade later that I found the language that allowed me to get a lot done without working hard. Perl.
It's been a great ride, but it's not over, not by a long shot. I have since retired from $work and now use Perl for projects at home. My heartfelt thanks to all of you for your generosity with your time and talent.
"It's not how hard you work, it's how much you get done."
This is not Perl related but my friends live here.
I ventured into Python and learned a lot. The theme is parallelization which is my passion. So, what better way to consume CPU cores than to explore the Mandelbrot Set in real time. Included in the GitHub repo are complementary CUDA and OpenCL demonstrations using PyCUDA and PyOpenCL respectively. To make things fast, Numba JITs Python code to C-like performance.
The various demonstrations work on FreeBSD, Linux, macOS, and Microsoft Windows. What about threads and GIL? Fortunately, not a problem. Meaning full CPU utilization on Windows. This is possible by specifying nogil=True for Numba and that releases the GIL.
A good friend of mine was up for a contract recently, and having passed the technical hurdles, he was sent the paperwork for the job (this was for a very large, well-known manufacturer, and was through a recruiting agency).
He read the contract, but had an issue with the part that said that in the event of a dispute between the agency and the manufacturer, he would be on the hook for all of the agency's legal fees. He communicated this to the agency, and their counter-offer was to suggest a full-time job instead.
That didn't happen (presumably because the two parties couldn't agree on a fee), so he was dropped from consideration.
I know about tilly's adventure, but .. being on the hook for someone else's legal fees? That's bizarre.
Has anyone else come across strangeness in employment contracts?
I sing with a group of top-notch musicians (our website) that I joined back in '98, because I wanted to challenge myself to become a better singer and performer. I did the same thing when I joined this website -- to learn and get better about everything to do with Perl.
Since my background in development languages was C and assembler, my early Perl code looked suspiciously like C. That was just my 'accent' talking. I've become a much more fluent reader and writer of Perl since then. And I owe that improvement to this community, to The Perl Foundation for supporting annual conferences, and to the regular Perlmonger meetings I attend (and host in Toronto).
I continue to be heartened about the progress that Perl development makes -- there are still regular releases, and Ovid is making progress with his OO project Corinna. And there are new modules and updates popping up on MetaCPAN every week. So much for the Greek chorus chanting 'Perl is dead' every year.
The quote I had planned to close with turns out to be made up (about Pablo Casal's contining to practise at age 80, because he felt he was '.. making progress.' here), but still, I like the idea of continuing to practise, even after 20+ years of using a technology, or being a musician. If I get a little better every day, every week, that's progress. I like that.
Some context: My initial problem of making sense of a pile of Excel VBA junk (see [OT] Finding similar program code) is largely solved, and I have started re-implementing the calculations in C#. C# is obviously not my first language, neither the second or third one. It's more somewhere around number 20. I've lost count. Ranting about a certain Hunchback-Gollum-Salvatore C derivate caused a misunderstanding and triggered a reply by jdporter:
wait - do you mean C#? Because imho C# is a great language.
Jdporter is not alone, I've already discussed a lot with my coworker, who really likes C#.
The re-implementation is my first C# project, after a tiny "hello world" command line program just to test the VS2019 installation.
I have already helped to debug some C# software, but rarely on the code level, more on the algorithm level, and of course some rubber duck debugging like "a < 10 looks wrong if you want to check that a is larger than 10".
C# is no huge surprise. It is just another language derived from C and some other languages, with OOP, and with its own set of quirks, strengths, and weaknesses. C# is designed for OOP, and supports OOP much better than some other langauges. OOP is not an afterthought, it is clearly part of the original design. Over the years, some syntatic sugar was added to the existing syntax, allowing to write quite short, but still readable code.
But I miss some really trivial things I'm used to in Perl:
The <=> and cmp operators together with ||
In C#, many classes (e.g. List<T>) implement a Sort() method that expects the C# equivalent of a compare function. You end writing something like this for a simple compare:
Well, CompareTo() is not pretty, but still acceptable. I would prefer the (invalid) C# example below, perhaps using operator overloading to call CompareTo() behind the scenes. Unfortunately, C# has no <=> operator that could be overloaded.
You can't use a.Foo.CompareTo(b.Foo) || a.Bar.CompareTo(b.Bar) in C#, because || is strictly boolean.
(Yes, I know that LINQ exists and has its own syntax plus extension methods to work with data in a way similar to SQL.)
Restart a loop block, bypassing the conditional. See redo. It simply does not exist in C#. You have to use goto, which is at least ugly; or use an inner loop, which opens another can of worms (see below).
I rarely need redo, but some of the calculations need a redo. In VBA, it was simply implemented via goto jumping backwards over some hundred lines of code. My C# code also uses goto, for the lack of a better loop control.
next LABEL, last LABEL, redo LABEL
Again, those do not exist in C#. You can not get out of an inner loop AND start the next iteration of an outer loop, exit the outer loop, or restart an outer loop. Again, you have to use goto. If you need all three variants in a single set of two nested loops, you need three labels: One at the start of the outer loop to simulate redo, one at the end of the outer loop to simulate next, and one after the outer loop to simulate last. You could also break out of the inner loop and use a bunch of helper variables, which don't make the code more readable.
Again, I rarely need to control an outer loop from an inner loop, but some of the calculations need that, too. Again, VBA used goto and jumped wildly around, and my C# code also uses goto where I could not avoid it.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Also, a thank you to JetBrains for such a great IDE (I use it in my day job every day for years now).
Features I like so far:
Good and smart syntax highlighting
Running a script inside the IDE console
Debugging with point and click breakpoints, watchers, evaluations (basically all you have in Java)
Jumping to implementation (i.e. Goto -> declaration/implementation actually works and drills into modules, etc.)
Find in path is a great IJ feature and works nicely with Perl code
Specific support for: mason, TT2, Mojolicious, and embedded Perl (I haven't tested all of these)
BTW, It may seem/feel ironic that a Java IDE is probably the best tool for Perl in 2021, and painful that we can't get our crap together with Padre, but hell, anything that helps Perl adoption is good in my book. Yeah, even if it's written in Java. Besides, many people currently making a living in the JDK ecosystem, could quickly try and adopt things like Mojo or Dancer if you can integrate seamlessly into their workflow so it's a win, win, win for everyone.
If you have any experience with helping out with Perl/Raku, there's a survey that could use your help. I took part a few weeks back, and had a really good conversation with the research assistant.
Dr. Ann Barcomb (her website) of the University of Calgary is conducting research to understand episodic, or occasional, participation in the Perl/Raku community, in collaboration with The Perl Foundation. The results of her research will be provided as a TPF report and will assist the community in improving practices for managing episodic participation. Please consider assisting them by taking the survey about your participation in the Perl/Raku community. The link to the survey is here.
After reading A short meditation about hash search performance because of Hash Search is VERY slow I wanted to investigate the performance of inserting into a hash and array as the number of existing elements increases. The methodology is to Benchmark::timeit() a number of insertions into an empty hash or an empty array. For array, insertion means "push at the end". My aim was to see if the time to insert is constant, linearly increasing with the number of items inserted. I believe this is confirmed. Inserts of N elements into a fresh hash are timed and recorded for different N. I did not just time only 1 insert because there's the suspicion that existing size may affect each new insert. I.e. it's faster to insert into an empty container. So I inserted N items and timed that in total.
Linear regression is used to build the relationship T = aX+b where T is the total time to insert X items into a fresh container. The error of the regression will be indicative of how well the hypothesis of constant insert time holds.
I interpret the results as follows: inserting into a hash or array takes constant time and is independent of size: e.g. if insertion of 1000 items into a fresh hash takes 1 unit of time then 2000 items take 2 units of time. Same with array. Caveat: hash keys provided by random_key() were extremely random. The confidence of this conclusion is stronger for arrays than for hash (the error of the linear regression). Inserting into an array is faster than inserting into a hash. Twice as fast in my computer/OS. Perl version used 5.32.1, Linux Fedora 5.13.19.
Caveat #2 The methodology is simplistic so please add on if you have better inspiration.
5' Edit: The ascii plot looks volatile but in reality the numbers show a nice linear relationship, which is confirmed by the low error of the least squares. Also "linear regression" and "least squares" mean the same in this post.
There have been some more edits within 20 minutes of posting. E.g. to clarify that array insert means push.
10000 array insertions took 1.00004911422729 seconds.
11000 array insertions took 1.09900379180908 seconds.
12000 array insertions took 1.20203304290771 seconds.
13000 array insertions took 1.32625269889832 seconds.
14000 array insertions took 1.42015385627747 seconds.
15000 array insertions took 1.50754404067993 seconds.
16000 array insertions took 1.60211801528931 seconds.
17000 array insertions took 1.70919871330261 seconds.
18000 array insertions took 1.80735301971436 seconds.
19000 array insertions took 1.90634799003601 seconds.
20000 array insertions took 1.99797105789185 seconds.
21000 array insertions took 2.09790301322937 seconds.
22000 array insertions took 2.20532703399658 seconds.
23000 array insertions took 2.30040597915649 seconds.
24000 array insertions took 2.40066504478455 seconds.
25000 array insertions took 2.50436305999756 seconds.
26000 array insertions took 2.59865713119507 seconds.
27000 array insertions took 2.70806193351746 seconds.
28000 array insertions took 2.79667997360229 seconds.
29000 array insertions took 2.89690399169922 seconds.
30000 array insertions took 2.99919009208679 seconds.
Y = 9.94971160764818e-05 * X + 0.0141616115322365 with error 0.0014576
Y : total time to insert X elements.
10000 hash insertions took 2.02198815345764 seconds.
11000 hash insertions took 2.21846413612366 seconds.
12000 hash insertions took 2.43116092681885 seconds.
13000 hash insertions took 2.62970495223999 seconds.
14000 hash insertions took 2.83560991287231 seconds.
15000 hash insertions took 3.04865097999573 seconds.
16000 hash insertions took 3.23556900024414 seconds.
17000 hash insertions took 3.44259905815125 seconds.
18000 hash insertions took 3.65537810325623 seconds.
19000 hash insertions took 3.85966873168945 seconds.
20000 hash insertions took 4.09639000892639 seconds.
21000 hash insertions took 4.35650420188904 seconds.
22000 hash insertions took 4.53428721427917 seconds.
23000 hash insertions took 4.74114084243774 seconds.
24000 hash insertions took 5.05467200279236 seconds.
25000 hash insertions took 5.18268871307373 seconds.
26000 hash insertions took 5.41770219802856 seconds.
27000 hash insertions took 5.68814396858215 seconds.
28000 hash insertions took 5.90737128257751 seconds.
29000 hash insertions took 6.0479040145874 seconds.
30000 hash insertions took 6.26542806625366 seconds.
Y = 0.000215204607047044 * X + -0.176900404356259 with error 0.0075377
Y : total time to insert X elements.
| + + +
6 |-+ 'hash2'
| B B
| B B
S | B B
E | B
C4 |-+ B B
O | B
N | B
D3 |-+ B B
S | B A A
+ A |
| B B A A A
| B A A A
2 |-+ A A A
| A A A
| A A A + + +
10000 15000 20000 25000
number of items
This is a patent office, Albert. Your job is to transform written patent applications into clear and precise language, and to study applications
and pick out the new ideas of an invention. These are the priorities. Where does it say that your priorities are rewriting the rules of the Universe,
unifying space and time, unifying radiation and matter, or demonstrating the existence of atoms?
Regrettably, I had to put you down as "poor" for "works well with others" and "shares credit appropriately".
You had no co-authors on your five papers, and your citations were quite skimpy: no citations at all in your June and September paper,
only one citation in your April paper, and not much better on the others.
You wrote that your special theory of relativity came to you after a discussion with your friend Michele Besso.
But you didn't even acknowledge him in your June paper. This is an area for improvement.
You seem to lack a flare for self-promotion. Lucky for us our PR department stepped in and changed your L/c2 equation into the much more marketable E = mc2.
Based on his performance as a patent clerk, I cannot recommend Albert for a promotion at this time.
Curiously, Einstein was passed over for promotion for three long years, until he "fully mastered machine technology",
remaining a lowly Patent Clerk Third Class at the Swiss Patent Office until 1 April 1906,
when he was finally promoted to Technical Expert Second Class.
In 1600 Giordano Bruno was found guilty of heresy by the Roman Inquisition.
He was then humiliatingly paraded naked through the streets of Rome (with his tongue lashed to prevent him speaking)
and finally burned at the stake, with his ashes thrown in the Tiber river.
His crime? Declaring that the stars are distant suns surrounded by their own planets.
I'm still amazed at how far ahead of his time Bruno was, his bold conjecture only
recently verified by exoplanet detections by the Kepler space telescope.
If there is a heaven, I hope Bruno smiles every time Kepler finds a new exoplanet and
I look forward to paying my respects to him at his statue,
located at the site of his execution.
The process in the scientific method involves making conjectures (hypotheses), deriving predictions from them as logical consequences,
and then carrying out experiments or empirical observations based on those predictions.
A hypothesis is a conjecture, based on knowledge obtained while seeking answers to the question.
The hypothesis might be very specific, or it might be broad. Scientists then test hypotheses by conducting experiments or studies.
A scientific hypothesis must be falsifiable, implying that it is possible to identify a possible outcome of an experiment or observation
that conflicts with predictions deduced from the hypothesis; otherwise, the hypothesis cannot be meaningfully tested.
Rigorous scrutiny. In science, all ideas (especially the important ones) must stand up to rigorous scrutiny. The culture of science does not value dogma.
Honesty, integrity, and objectivity.
Credit where credit is due. Scientific research articles always provide a list of citations, crediting other scientists for ideas, techniques, and studies that were built upon by the current research. The number of citations a paper receives can help indicate how influential it was, since important research influences how other scientists think about a topic and will be cited many times in other papers.
Adherence to ethical guidelines.
Update (see erix response below): the four Mertonian norms (often abbreviated as the CUDO-norms) are:
Communism: all scientists should have common ownership of scientific goods (intellectual property), to promote collective collaboration; secrecy is the opposite of this norm.
Universalism: scientific validity is independent of the sociopolitical status/personal attributes of its participants.
Disinterestedness: scientific institutions act for the benefit of a common scientific enterprise, rather than for the personal gain of individuals within them.
Organized skepticism: scientific claims should be exposed to critical scrutiny before being accepted: both in methodology and institutional codes of conduct.
Because it undermines science, scientists take misconduct very seriously.
In response to misconduct, the scientific community may withhold esteem, job offers, and funding,
effectively preventing the offender from participating in science.
There are also strict rules around scientific publications, as detailed at publishing process
and responsible referencing:
After erasing all signs of your identity, your paper will be sent to 2–3 other scholars who have done research in the same field for review; they will not know who you are or who the other readers or reviewers are.
The reviewers will spend a few months reading your submission, double-checking your methods and or claims/citations from other source; they will then send it back to the manuscript editor with commentary and one of the following votes: accept for publication; revise and resubmit (the most common outcome); reject for publication. The reviewers may further write some commentary, for example, a need to redo the experiment using slightly different equipment, or ask you to read through certain books or articles others have published and incorporate that into your work.
The reviewers have to judge the work based on what you have written and what you use as evidence, not who you are or whether you have a fancy degree.
Though the traditional Scientific method has served us well, it seems we need
new methodologies to tackle the urgent problems facing us today.
On an evolutionarily miniscule timescale, cultural and technological processes transformed our species’ ecology.
These changes that have transpired over this period have come about largely to solve issues at the scale of
families, cities, and nations; only recently have cultural products begun to focus on solutions to
worldwide problems and wellbeing.
Yet we lack the ability to predict how the technologies we adopt today will impact global patterns of
beliefs and behavior tomorrow
... social interactions and external feedback make it difficult, if not impossible, to reason about
cross-scale dynamics through argument alone (i.e., these are complex adaptive systems).
Humanity faces global and existential threats including climate change, ecosystem degradation, and the prospect of nuclear war.
We likewise face a number of other challenges that impact our wellbeing, including racism, disease, famine, and economic inequality.
Our success at facing these challenges depends on our global social dynamics in a modern and technologically connected world.
Given our evolved tendencies combined with the impact of technology and population growth, there is no reason to
believe that human social dynamics will be sustainable or conducive to wellbeing if left unmanaged.
Other crisis disciplines thrive on a close integration of observational, theoretical, and empirical approaches.
Global climate models inform, and are informed by, experiments in the laboratory and the field.
Mathematics describing disease dynamics suggest treatment paradigms in medicine, which can be tested and validated.
A consolidated transdisciplinary approach to understanding and managing human collective behavior will be a monumental
challenge, yet it is a necessary one. Given that algorithms and companies are already altering our global patterns of
behavior for financial reasons, there is no safe hands-off approach.
As argued convincingly above,
the traditional scientific method, requiring laborious peer review for example,
is too slow for crisis disciplines and better alternatives must therefore be urgently sought.
On a more positive note, we've been forced to do this sort of thing before - the Manhattan Project and rapid vaccine development during our current COVID-19 pandemic spring to mind.
Here in the UK there is currently a government scheme to get young people into work. The Kickstart Scheme pays the young person minimum wage for 25 hours per week for 6 months. We have applied to take on two young people under the scheme. Most applicants have played with React at most but I am interviewing a graduate tomorrow. On his CV he has C, Python and R which has been done as part of his Physics degree plus Python and Shell Scripts on a Raspberry Pi as a hobby.
I know absolutely nothing about R.
From my very limited knowledge of Python, I believe it is broadly in the same group of languages as Perl. Therefore, the skills this applicant already has in Python should be relatively easily transferrable to Perl - is that a fair assessment???
Any suggestions for me bearing in mind the applicant has had no real workplace experience?
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor