Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation


( #480=superdoc: print w/replies, xml ) Need Help??

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").

User Meditations
If 6 Was 9
6 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 15, 2018 at 14:00
    You know that feeling, when the big program you've been working on approaches completion, and you're scanning for those invisible bugs the others will find when running your code. That's when I saw something like this somewhere between lines 6000 and 7000:
    my $one = 1; my $six = my $nine = 9; print $six; # prints 9
    I didn't know you could chain lexical declarations like that! The bug survived for months because $nine was 0 and $six was supposed to be an empty string. Playing around with it reveals more questionable behavior:
    #!/usr/bin/perl -l use strict; use warnings; use diagnostics; print my $J = my $A = my $P = my $H = 'Just',' Another ','Perl',' Hacker';
    Does that look strict? :-)
Perhaps it's time to look at Perl 6 ?
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 12, 2018 at 22:48
    Interesting meditation on Perl from a programmer dealing with a "complete nightmare" after 8 years of Beautiful is better than ugly:

    "But seriously, many computer scientists have fallen into the trap of trying to define languages like George Orwell’s Newspeak, in which it is impossible to think bad thoughts. What they end up doing is killing the creativity of programming.

    A more insidious trap, promulgated in many places these days (including the most recent Discover magazine), is that a computer program should be beautiful. Let me tell you that when it comes to computer languages, this is totally bogus. If you want to do beautiful art, you don’t go out and buy a beautiful canvas, and a beautiful brush, and a beautiful palette, and slather beautiful paints on it. If you want to write beautiful poetry, this doesn’t happen because you started with a beautiful language. Languages are an artistic medium. I don’t want Perl to be beautiful–I want you to write beautiful programs in Perl.

    Finally, I believe that any language essentially should be out of control, because no one person or institution is capable of controlling a language (or a culture, for that matter) without destroying it. Living languages are always a cooperative effort, and I want Perl to be a living language."


Perl Web Security: 15 years of lessons not learned by inferior new languages
No replies — Read more | Post response
by Anonymous Monk
on Oct 10, 2018 at 14:25
    2001: Perl CGI HTTP_PROXY bug fixed! (by Merlyn :-)

    15 years before nginx:

    15 years before Apache:

    15 years before PHP:

    15 years before Python:

    15 years before Go (Golang):

    Who do you trust?


    2018-10-21 Athanasius changed <h1> tags to <h3>

the sad reality of perl
3 direct replies — Read more / Contribute
by morgon
on Oct 09, 2018 at 18:15
The joy of Perl, 20 years later
1 direct reply — Read more / Contribute
by Anonymous Monk
on Oct 09, 2018 at 10:55
Writing Popular Perl Software
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 07, 2018 at 20:27

    Writing Popular Perl Software

    Recently published a list of top keywords for their googsearch:

    Having this information is like asking a sentient billion human brain AI the question, "perl"?

    The answer was nine nouns in precedential order:

    $ perl? $ sql linux python mysql cgi regex foreach cpan download $ _

    The world needs Perl to:

    1. Interact with SQL databases.
    2. Work with Linux.
    3. Do something (with, about, for, etc) Python.
    4. Interact with MySQL databases.
    5. Provide the Common Gateway Interface.
    6. Match regular expressions.
    7. Process each item in a list.
    8. Expand through modules.
    9. Download!


    "As of 2014, Google used a heavily customized version of Debian (GNU/Linux). They migrated from a Red Hat-based system incrementally in 2013."


    "Perl is just another high level programming language that supports object-oriented, procedural and/or functional programming.

    Lot of Debian and GNU tools, use Perl. Lot of system core components, packaging internals and other critical points, rely on Perl versions.

    If you've some unmet requirements about the Perl interpreter version, TIMTOWTDI

    (There Is More Than One Way To Do It)

    2018-10-20 Athanasius removed code tags, added paragraph tags, linkified links, etc.

a look at [Lingua::Bork]
1 direct reply — Read more / Contribute
by Aldebaran
on Sep 19, 2018 at 12:30

    I've been wanting to write a meditation on encodings or Path::Tiny, but I always seemed to come up with a substantive perl question, which is more the purview of Seekers of Perl Wisdom. A confluence of events makes me interested in the word "bork." I had believed it to be an american english word, a verb that had been called into being in the 80's, and surprised to read marto describe File::Slurp as "borked." I think he took it at as a synonym for "kaputt," "busted," "broken," "f*****." I thought, gosh, that's a different meaning than the one I use it for.

    Imagine my surprise as I'm surveying the cpan material for Lingua, and I see Lingua::Bork 'bork'. At first I thought it was a joke, then a con, but then I realized it was a function that rendered text in the idiom of the swedish chef from the muppets show. The assignment is explained in this pdf.

    What makes this timely is the etymology of the american verb. Wiki included the meaning I remember, when some feminist said of Clarence Thomas, "we're going to bork him." This declaration was widely broadcasted and galvanized conservatives. This verbing supplanted an earlier passive verb "borking," where Bork would substitute his opinion for precedent.

    What brings this all into focus is that Robert Bork was voted down by the US senate, replaced by Anthony Kennedy, who retired recently, and now we have all the same forces arrayed against each other again. It will be the best of times, the worst of times, and the end of life as we know it, if you can stand to watch tv. Mormon Methusalah Orrin Hatch will say the same things. If Kavanaugh isn't confirmed, we'll get someone else who thinks that speech is money, corporations are people, and that women cannot be trusted to make decisions about their bodies.

    One thing I like to do when the parade of Not Normal is blaring at high volume is perl. I won't worry about the russia probe because I've got other russian stuff to do. I can't change institutions or states, but I can change the scripts I work with. I can make them more useful, gain a competitive edge. Many times I run an example of someone else's code, leave it sitting for a while, then come back to it when need for it arises.

    Other times, perl is for distraction, education or entertainment, and it is in this vein that I introduce

    #!/usr/bin/perl -w use 5.011; use utf8; binmode STDOUT, ":encoding(UTF-8)"; use Lingua::StopWords qw( getStopWords ); my $stopwords = getStopWords('en'); use Lingua::Bork 'bork'; say bork("This is the conjunction junction."); my $sentence = "Many think this judge's nomination will lead to a rest +riction on abortion."; my @words = split / /, $sentence; my $stop = join ' ', grep { !$stopwords->{$_} } @words; say $stop; say bork($stop); __END__

    This shows how Lingua::Stopwords works as well as Lingua::Bork:

    $ ./ Thees ees zee cunjooncshun jooncshun. Bork Bork Bork! Many think judge's nomination will lead restriction abortion. Muny theenk joodgea's numeenashun veell lead restreecshun aburshun. B +ork Bork Bork! $

    Maybe it helps to not take matters so seriously....

modulo 1 (%1) and fractional part of a number
3 direct replies — Read more / Contribute
by JBCookin
on Sep 11, 2018 at 03:24

    Is there a reason Perl could not use %1 to indicate the fractional part of a number. As far as I can tell, right now %1 always returns 0.

    This feature would be a much simpler way of getting the fractional part of a number than anything else I've seen, and it's hard to see any downside.

$foo magazin - giveaway
1 direct reply — Read more / Contribute
by holli
on Sep 10, 2018 at 14:23
    Guys I am in the process of mininmizing the amount of stuff I have. While going trough my stuff, I have found some old issues of the "$foo - Perl Magazin" I'd like to give away if somebody is interested. Otherwise they go to the recycling.
    Issues: 3/2007, 4/2007, Summer 2007, 1/2008, 2/2008, 4/2008


    You can lead your users to water, but alas, you cannot drown them.
(job) security through obscurity
3 direct replies — Read more / Contribute
by xyzzy
on Sep 08, 2018 at 22:42

    While searching for "eyetee"-related jobs in my area, I was surprised to see a number of listings for Perl developers. After looking at one, I was no longer surprised:

    We need someone to come in and Crack open, modify, and replace some old code written in Perl.
    Translation: some idiot who worked here 15 years ago wrote a bunch of Perl scripts that our entire system runs on, and none of our current staff can decipher them.

    Offered extremely flexible hours, full-time or part-time, or even a work-from-home arrangement. Really made me appreciate how valuable our arcane art is.

    And they all scoffed at me for claiming that Perl is still marketable in $current_year...

    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    "Structurally, Perl is a brainf*ck comparable to that of brainf*ck."
Breaking Tie::Hash into three modules
5 direct replies — Read more / Contribute
by afoken
on Sep 08, 2018 at 14:26


    This meditation was triggered by Re^3: How to tie a hash to a class.

    The Problem

    Why can we do this ...

    package My::Hash; use strict; use warnings; use parent 'Tie::Hash'; 1;

    ... but not this?

    package My::Hash; use strict; use warnings; use parent 'Tie::StdHash'; 1;

    Why do we have to write this instead?

    package My::Hash; use strict; use warnings; use Tie::Hash (); our @ISA='Tie::StdHash'; 1;

    Or, even worse, this, following the documentation found in Tie::Hash?

    package My::Hash; # NO use strict; or things will break! use warnings; require Tie::Hash; @ISA='Tie::StdHash'; 1;

    A little bit of history

    Well, at some point in time, someone must have thought it was clever to put all three classes Tie::Hash, Tie::StdHash, and Tie::ExtraHash into the same file, Tie/ Looking at, that must have happened before 1996-02-03. So this oddity is embedded deep in Perl's history.

    At that time, Tie::Hash was still named TieHash, and Tie::StdHash was still named TieHash::Std. Tie::ExtraHash did not exist. And for reasons that are not clear to me, TieHash::Std inherited from TieHash. TieHash::Std reimplemented each and every method, and so only new() was really inherited from TieHash. That is the most useless method in the entire file, because tie never calls it. The TieHash::TIEHASH() constructor adds some extra work just to check for a new() implementation, and that's still there.

    Three days after the first version, the classes were renamed to their current names.

    Six years later, Tie::ExtraHash appeared in the same file, and it did NOT inherit from Tie::Hash. At the same time, Tie::StdHash stopped inheriting the nonsense new() constructor from Tie::Hash:

    # @ISA = qw(Tie::Hash); # would inherit new() only

    In all of the following versions up to the latest from 2013, Tie::ExtraHash never started inherited from Tie::Hash, and the @ISA line in Tie::StdHash was never commented back in.

    Cleaning up the mess

    First, Tie::ExtraHash

    As shown, Tie::ExtraHash never inherited from Tie::Hash, so it is completely safe to move it into a separate file. Just cut the last 13 lines from Tie/ and paste them into a new file Tie/

    package Tie::ExtraHash; sub TIEHASH { my $p = shift; bless [{}, @_], $p } sub STORE { $_[0][0]{$_[1]} = $_[2] } sub FETCH { $_[0][0]{$_[1]} } sub FIRSTKEY { my $a = scalar keys %{$_[0][0]}; each %{$_[0][0]} } sub NEXTKEY { each %{$_[0][0]} } sub EXISTS { exists $_[0][0]->{$_[1]} } sub DELETE { delete $_[0][0]->{$_[1]} } sub CLEAR { %{$_[0][0]} = () } sub SCALAR { scalar %{$_[0][0]} } 1;

    Then, Tie::StdHash

    For the last 16 years, it seems that nobody complained about Tie::StdHash no longer inheriting the useless new() from Tie::Hash. So I am very sure that we can also move that class safely out of Tie/ From the edited Tie/, cut the last 17 lines and paste them into a new file Tie/ Add a trailing 1; and remove the @ISA line completely:

    # The Tie::StdHash package implements standard perl hash behaviour. # It exists to act as a base class for classes which only wish to # alter some parts of their behaviour. package Tie::StdHash; sub TIEHASH { bless {}, $_[0] } sub STORE { $_[0]->{$_[1]} = $_[2] } sub FETCH { $_[0]->{$_[1]} } sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} } sub NEXTKEY { each %{$_[0]} } sub EXISTS { exists $_[0]->{$_[1]} } sub DELETE { delete $_[0]->{$_[1]} } sub CLEAR { %{$_[0]} = () } sub SCALAR { scalar %{$_[0]} } 1;

    Third, Tie::Hash

    The most obvious problem first: Append a trailing 1; or else loading Tie::Hash will fail.

    Now that we have cleaned up everything, legacy knocks at the door, complaining about modules failing to inherit from Tie::StdHash after loading only Tie::Hash. So, we have to load the two modules, just to avoid legacy trouble. Adding two use lines is easy:

    use Tie::StdHash; use Tie::ExtraHash;

    A little bit of cleaning up

    Both Tie::StdHash and Tie::ExtraHash lack a version number, so add our $VERSION = '1.06' to both files, and bump $VERSION in Tie::Hash to 1.06, too.

    All three classes should use strict; use warnings;.

    The POD

    Tie::StdHash and Tie::ExtraHash have no POD at all. We could work around with something like this:

    =head1 NAME Tie::StdHash =head1 SYNOPSIS See L<Tie::Hash> =head1 DESCRIPTION See L<Tie::Hash> =cut

    A Patch

    Instead of adding workarounds, we could clean up the POD in Tie::Hash, move the parts documenting Tie::StdHash and Tie::ExtraHash into the respective files, and clean up the examples to 21st century Perl.

    Here is a diff, based on the current HEAD:

    Should anyone get paranoid about legal stuff: This diff is free software, use it under the same license as Perl (perlartistic).


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
"link tax", "censorship machines" and EU's Looming Internet Catastrophe
2 direct replies — Read more / Contribute
by marto
on Sep 07, 2018 at 07:14

    I believe that this Cory Doctorow article is worth reading, and acting upon: Why the Whole World Should Be Up in Arms About the EU's Looming Internet Catastrophe. An extract:

    Under Article 11 — the "link tax" — online services are banned from allowing links to news services on their platforms unless they get a license to make links to the news; the rule does not define "news service" or "link," leaving 28 member states to make up their own definitions and leaving it to everyone else to comply with 28 different rules.

    Under Article 13 — the "censorship machines" — anyone who allows users to communicate in public by posting audio, video, stills, code, or anything that might be copyrighted — must send those posts to a copyright enforcement algorithm. The algorithm will compare it to all the known copyrighted works (anyone can add anything to the algorithm's database) and censor it if it seems to be a match.

Perlbrew change
No replies — Read more | Post response
by stevieb
on Sep 06, 2018 at 18:47

    I was away for fire evacuation during the last month, with the previous two months dedicated to other significant disasters spread across my life.

    Looks to me that perlbrew changed back to a listing I'm familiar with in regards to the available command, and I have to say, it makes things like home.

    pi@pi-test6:~ $ perlbrew available perl-5.29.2 perl-5.28.0 perl-5.26.2 perl-5.26.1 perl-5.26.0 ...

    This is apparently via a change recently, and this is what I have:

    pi@pi-test6:~ $ perlbrew version /home/pi/perl5/perlbrew/bin/perlbrew - App::perlbrew/0.84

    Now that I'm getting back to normal life after a fsckn adventure I wish on nobody, I'd like to hear from the Windows users what features or changes you'd like in `berrybrew`. I have a lot to give back to, and a lot to give back for, but give me your input and I'll see what can be done.

    For everyone, thanks for the love, and as always, tell me how I can fix my code to make life easier.

RFC: Self Assessment Perl
6 direct replies — Read more / Contribute
by LanX
on Sep 05, 2018 at 14:38
Last and Least
6 direct replies — Read more / Contribute
by liz
on Aug 30, 2018 at 17:55

    This is the last node that I will write in PerlMonks. It was fun, mostly. It isn't anymore, not even on average.

    I wish the Perl Monks strength.


Add your Meditation
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2019-01-18 07:23 GMT
    Find Nodes?
      Voting Booth?
      After Perl5, I'm mostly interested in:

      Results (321 votes). Check out past polls.