Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number


( #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
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.


One of those odd compiler messages...
3 direct replies — Read more / Contribute
by ait
on Aug 29, 2018 at 22:58

    Thought I'd share something funny with ye fellow monks...

    $ ./ 3000
    given is experimental at ./ line 86.
    when is experimental at ./ line 87.
    when is experimental at ./ line 88.
    Bareword "shit" not allowed while "strict subs" in use at ./ line 46.
    Execution of ./ aborted due to compilation errors.

    The culprit:

    sub process_get {
      my $client = shit;
      my $url = shift;
      my $data = shift;

    Come to think of it, this should actually be pretty common but it's the first time that's ever happened to me in about 20 years of Perl hacking!

    Good thing I use strict and warnings in all my code ;-)

OO systems and Perl 5 (Was: Recap: Future of Perl 5)
3 direct replies — Read more / Contribute
by RonW
on Aug 28, 2018 at 19:50

    Ovid's Recap: The Future of Perl 5 got me curious, so I did some searching and found something interesting.

    Object creation in Perl compared to Smalltalk (the putative parent language of OO languages): They are surprisingly similar.

    Using Ovid's Point example, in Smalltalk:

    Object subclass: 'Point' instanceVariables: 'x y ' x ^x x: coord x := coord y ^y y: coord y := coord init x := Float new. y := Float new.

    Then to create an instance:

    p := Point new. p init. p x: 1.5. p y: 1.5.

    Doesn't that look a lot like:

    my $p = bless {}, Point; $p->init; $p->x(1.5); $p->y(1.5);

    For a friendlier object creation, you can define a class method to do all that:

    newX: xc Y: yc p := Point new. p init. p x: xc. p y: yc. ^p


    Point newX: 1.5 Y: 1.5.

    Also, Smalltalk's new is a method inherited from the Object class and can be overridden by defining a new method as a class method of any user defined class. I'm leaving that as exercise for the readers.

    So, maybe Perl 5's much maligned OO system can be blamed on Smalltalk. Not sure what else Larry et al had available to look at, but looks like Smalltalk had a strong influence.

    Still, there is hope for Perl 5's OO system.

    For those who've forgotten or are not familiar, Perl 5 has an equivalent to Object called UNIVERSAL. All classes in Perl 5 inherit from UNIVERSAL.

    In theory, Perl 5 could provide a default new method for all classes by defining a new method in

    Maybe Ovid can present a compelling enough argument to do that. That would be a great first step.

    But, since I'm writing this comment, I'll suggest 2 additions to

    sub init { # Nothing to do, this is just here so classes don't have to define + init } sub new { my $class = shift; my $object = bless {}, $class; $object->init(@_); return $object; }

    I'm sure someone will come up with a better default new. This one is just an example of what could be done.

    Disclaimer: None of this code is tested. YMMV

The Perl Conference - Glasgow 2018 - A summary
2 direct replies — Read more / Contribute
by marto
on Aug 24, 2018 at 08:48
The war against Perl, by random wikipedia editors
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 23, 2018 at 22:13
    For many years Perl was part of the Model–view–controller page at wikipedia. At some point the Catalyst and Maypole links were quietly deleted and now everything except Perl gets a nod. This is not an isolated incident.

    Of course anyone can edit wikipedia: Let's put Perl back on the map!

Perl as mobile language
3 direct replies — Read more / Contribute
by aartist
on Aug 23, 2018 at 14:09
    I was looking at Language Comparison 2018 and see that Perl is missing in the list of 'mobile' languages. Is there any chance of mobile development with Perl ? Or why not?
Recap: The Future of Perl 5
9 direct replies — Read more / Contribute
by Ovid
on Aug 23, 2018 at 09:03

    Recently in The Future of Perl 5, there was a discussion of my keynote at the Glasgow Perl Conference. Rather than wade into that thread, I thought I should provide a brief explanation of what I was trying to achieve: a modest proposal (er, pardon that description) that was achievable, still Perl, and would not only return the conciseness of the language but would also allow Perl 5 to leapfrog many popular dynamic languages in terms of functionality (I'll skip the Perl 6 discussion and the inline discussion). This isn't a large-scale strategy to "fix everything", but a couple of small (ha!) steps which would make Perl much easier to write and maintain in large companies.

    Perl has a long, strong history. Unfortunately, because Perl was the trail-blazer for many techniques taken for granted today, it sometimes went down dead-ends and those who followed learned from Perl. Perl also stole much from other languages and it's time to steal a bit more. Consider, for example, the lowly Fibonacci function. It would be natural to write it like this:

    sub fib { my $nth = shift; return $nth if $nth <= 1; return fib( $nth - 1 ) + fib( $nth - 2 ); }

    That looks like a perfectly natural way to write that function and if you pass it expected values, it returns expected results (we'll ignore the performance and memory issues as those aren't unique to Perl 5). But what if you pass it a -2? Or an undefined value? Or a string? Or a float? Or a typeglob? Or, or, or ...

    At, we're used to working with large clients and large codebases and that sort of coding trips us up many times. It's hard building a large system, slinging data around left and write (er, "right"), without hitting these problems. In terms of maintenance, it's a nightmare. For short scripts, it's ok. When you're trying to build large-scale systems, it's a constant drag on developer time, even with tests (because you have to spend time and money to write tests to verify you've correctly handled what the language itself handles in many other languages). To write a robust Fibonacci function, you might write something like this:

    sub fib { croak("…") if @_ != 1; my $nth = $_[0]; croak("…") if not defined $nth; croak("…") if $nth !~ /^+?\d+$/a; return $nth if $nth <= 1; return fib( $nth - 1 ) + fib( $nth - 2 ); }

    But let's be honest: almost nobody does that and if you did, you'd be spending more time and money on something you often don't have to spend time and money on in other languages.

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 having an uproarious good time at the Monastery: (10)
    As of 2018-09-24 13:29 GMT
    Find Nodes?
      Voting Booth?
      Eventually, "covfefe" will come to mean:

      Results (191 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!