Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses


( #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
RFC: MVC::Neaf aka Not Even A Framework, part 2
No replies — Read more | Post response
by Dallaylaen
on Oct 18, 2016 at 16:10

    Hello dear fellow monks,

    After weeks of hesitation, I finally decided to share a piece of work called MVC::Neaf. Neaf [ni:f] stands for Not Even A Framework.

    It aims to keep things simple and straightforward, while maintaining some degree of separation between logic and presentation.

    Not to repeat myself, here's the original post.

    I know there's a lot to do, so I would appreciate any feedback. If you dare to try it out, please send bug reports and feature requests to github.


RFC: Not Even A Framework
1 direct reply — Read more / Contribute
by Dallaylaen
on Oct 02, 2016 at 10:31

    Hello dear fellow monks,

    It's Sunday, and I would like to confess to an awful sin of writing my own web framework from scratch. Yes, it's 2016, there are Dancer, Catalyst, Mojo, Kepl, and a dozen less known examples. I mostly did it for my own education, as well as to look at possible ways of handling the nuisances that have been plaguing me throughout my two last jobs. Yet I see some not so bad ideas in there and would like to share and possibly get some critique.

    It's called Neaf [ni:f], which stands for Not Even A Framework.

    Much like Dancer, it splits an application into a set of handler subroutines associated with URI paths. Unlike Dancer, however, it doesn't export anything (except one tiny auxiliary sub) into the application namespace. Instead, a know-it-all Request object is fed to a handler when serving request, like in OO or Kelp.

    The response is expected in the form of unblessed hash reference which is in turn fed to the view object for rendering (Template Toolkit and JSON/JSONP currently supported, also Data::Dumper for debugging). Also the return value may contain some dash-prefixed switches altering the behavior of Neaf itself - awful looking, yet visible and simple way of doing it without going for a more complex structure.

    Unlike anything I've seen so far, and much like Perl's own -T switch*, it offers no (easy) way to get user inputs without validation, either through regexp, or through a form validator. (Regexp-based one is in stock, LIVR also supported).

    My not-so-impressive feature list so far:

    • GET, POST, and HEAD requests, query parameters (multivalues not done yet), uploads, cookies, and redirects;
    • Template::Toolkit, JSON::XS view out of the box;
    • Can serve raw generated content (e.g. images) and static files (like css/js);
    • CLI-based debugging (can simulate posts, uploads, cookies etc);
    • Can serve delayed or unspecified length replies, or do custom actions after the request is finished;
    • cookie-based sessions supported (no storage drivers available out of the box yet, though);
    • Form validation and resubmission;
    • Half-decent example directory and 79% overall test coverage.

    The following is a valid application and can run as a CGI script, a PSGI app, or under Apache as a mod_perl handler**:

    use strict; use warnings; use MVC::Neaf; MVC::Neaf->route( "/" => sub { my $req = shift; return { -template => \'Hello, [% name %]!', -type => 'text/plain', name => $req->param( name => qr/\w+/, "Stranger" ), }, }); MVC::Neaf->run;

    So here it is: Thanks for reading this, and hope you enjoy the rest of the weekend.

    *That said, I have not seen it often in production, certainly not in big apps with convoluted logic.

    **Setting up a handler requires a little extra work though - see apache.cgi file in the distribution.

    UPDATE Uploaded to CPAN.

Don't post bad code!
5 direct replies — Read more / Contribute
by afoken
on Sep 26, 2016 at 16:46

    The thread Declaring and checking content of variables with consecutive names and especially the answer Re: Declaring and checking content of variables with consecutive names triggered this meditation.

    There is nothing special about this thread or this answer, it's just one of those FAQs (in this case "How can I get variable variable names"). People explain how to do the job properly, and some other people can't resist showing that there is a way how to force perl into using the stupid variant. I vagely remember threads where people tried to find even more stupid ways to "solve" a cleanly solveable problem.

    Yes, we can force perl into doing the most stupid things. Yes, it's cool to know how to mess with the inner workings of perl. But no, we should not show beginners the most dirty ways first. Not even with warnings not to use the dirty ways in production code. "Just do as I say, don't do as I do" is no good motto, not for teaching beginners.

    Why? Because there are lots of beginners out there, who either don't have time to or are unwilling to learn how to use perl. They just want fast results, they don't care about maintainability or improving their skills. Imagine what happens when they get ten answers linking to FAQs, HOWTOs, documentation, or showing examples of the right way, but require a little bit of thinking; and one or two answers showing how to abuse perl into the way they are currently thinking.

    "There is nothing humans would not do to avoid thinking."
    -- Found on a pinboard in a computer laboratory in my univerity

    This way, bad practices propagate, resulting in crappy perl scripts.

    Let's make it hard for the unwilling and the people in a hurry to find bad code, bad examples. Posting sane examples is good, improving a code example posted is even better.

    But what about golf?

    Perl golf is fun, true. Replacing pages and pages of code with 20 characters of "line noise" with the same result is deeply impressive. But do we have to show our golf skills in beginner threads? I don't think so. Create a new thread, link to the beginner's thread, and name it "Golf Challenge". Or at least start a golf posting by explaining that this is not a real answer, but a golf challenge for the experts.

    Are one-liners bad?

    (A meditation in a meditation)

    It depends. Short one-liners for one-time use are ok. But for anything more complex than one or two, maybe three explicit instructions (not counting the implicit loops in perl -p and perl -n) should be in a script. And if the one-liner is to be reused, it should instead be a script, too.


    • One-liners require that you remember quite complex "line noise". So you very likely store them in a file. What's the difference to using a real script? It's just harder to use, as you need to copy-and-paste.
    • Quoting rules differ with different shells (and different operating systems), so you need to adapt the one-liners, especially the arguments to perl -e and perl -E, to the shell currently in use. Scripts don't have this problem.
    • Scripts can have nice names. cleanup-foo is easier to remember, easier to type, and shows the intention more clearly than perl + 10 perl command line options + -e plus 80 characters of "line noise" in quotes differing from shell to shell.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Code "taste", coding guidelines, and revision control systems
3 direct replies — Read more / Contribute
by afoken
on Sep 16, 2016 at 17:24

    (Just thinking out lout a little bit more after writing Re: Starting a New Script ...)

    A long time ago, in a galaxy company far, far away ...

    Co-worker IH asks: "Who wrote this code?"

    Me: "Hmm, definitively not me. And far too structured to be written by HK."

    IH: "Yes, I agree. Looking at the names of the identifiers hints at DF, or maybe JF during his first months [when he learned from DF]. It's full of three letter acronyms."

    Me: "But JF would have added at least some comments. There is not a single comment, and not a single bit of code that's not absolutely required. Tight, but elegant. DF?"

    IH: "Yes, definitely DF. But what does it do?"

    Me: "Well, let's start analysing it ..."

    And of course, we were right. DF wrote the code, and nobody else touched it after that. Just for fun, we tried that with other pieces of code the team members wrote over the years, and we were often right. We could even guess who wrote the original code, and who changed it later.

    When we later explained our little game and its origin to non-IT people, we compared it to wine tasting, and to guessing an author from a piece of text.

    In the next episode, same galaxy company, but a different team:

    JF, a hardly ever swearing co-worker, asks: "What the *BEEP*? Which *BEEP* *BEEP* has written this *BEEP* *BEEP* *BEEP* piece of code?"

    Me: "Show me."

    JF: "Here you are."

    Me: "Argh! Get it off my screen. It hurts my eyes! It hurts my brain! Get it off! GET IT OFF!"

    Me, after wiping off some tears: "Well, it roughly looks like code generated by $StupidMouseClickingCodeGenerator. But why the heck did the author use that *BEEP* tool? It's completely useless here! We are on a completely different target system!"

    JF: "If your only tool is a hammer, every problem looks like a nail. Some clueless worker from the client?"

    Me: "Nope, the client does not access that part of the code. It's part of our setup routine. And the client would use tools for the right target."

    JF: "So AG?"

    Me: "Yes, definitely AG. Who else would use a hammer for a brain surgery?"

    JF: "AG definitively needs to learn $ComputerLanguage."

    Me: "And our system. It's three months, and still AG has absolutely no clue of what happens here. You will tell AG. I can't do that without insults and swearing."

    And of course, we were right again.

    Using revision control systems makes the guessing game a lot less interesting (svn log, svn blame), and using strict coding rules and code templates generates more uniform code across the team.

    But still then, without looking at the logs, you can see differences in the way team members write code. And you can often identify who wrote a piece of code: "Soft factors" like the length and complexity of subroutines, naming of identifiers, style of the embedded documentation (POD, doxygen), systematic spelling errors in identifiers and documentation, preferred algorithms, and so on.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Starting a New Script
8 direct replies — Read more / Contribute
by LloydRice
on Sep 16, 2016 at 09:48

    How do you start a new script? Do you just open a blank editor page and start typing?

    I have written a Perl Code Builder that may be of some interest to somebody. To run it, you specify any number of capabilities this script should include, out of a catalog of a couple of dozen areas. Available capabilities range from a few simple trig functions and file read/write loops to a fairly elaborate PostScript code writer. You then open this "outline" script and finish rounding out the half-written pieces of code to do the current job. Since writing this, I have never started a new script from a blank slate.

    Would this be of interest to anybody? If so, I will make it freely available.

    Do similar things already exist? If so, I have missed seeing them.

    Lloyd Rice

[emacs] RFC live formating / tidying while I type
1 direct reply — Read more / Contribute
by LanX
on Sep 08, 2016 at 15:32

    I always wanted to have live formatting as I type Perl code.

    The usual advice to pipe a text selection through perltidy is just too slow, and furthermore you might want to have only a visible snippet formatted to keep control, and tidy can fail here (emacs is mostly very tolerant)

    The following code called with M-x my-indent-block is re-indenting the surrounding block you are in. The devadvice binds it to the cperls electric-semi feature which automatically does a return and and indentation of the following line (see M-x customize-group RET cperl-autoinsert-details for details)


    for my$scalar(1..10){print"$scalar"."txt";}
    for my $scalar (1..10) { print"$scalar"."txt"; }
    NB: this is work progress but it's by far faster than perltidy
    (defun my-indent-block () "reindent surroundig expression" (interactive) (save-excursion (backward-up-list) (cperl-indent-exp) ) ) (defadvice cperl-electric-semi (after my-electric-indent-context) "indent whole context surrounding block/context" (my-indent-block) ) (add-hook 'cperl-mode-hook (lambda () (local-set-key (kbd "M-C-q") 'my-indent-block ) ) )

    • Defadvice is a kind of wrapping, I tried to bind it to cperl-indent-line to always indent the whole block whenever and indentation is triggered (there are many ways to do so in cperl-mode) but this is causing an infinite recursion , since cperl-indent-exp calls cperl-indent-line. (this is for sure solvable with some kind of flag, but I'm tired now :)
    • Toplevel In filescope this doesn't work cause there is no up-list! Thats good, because I didn't want to reindent distant code, without visual control. But it's still pretty easy in elisp to catch the error and to react otherwise, one option is to just reindent one paragraph or the whole file if that option is set.
    Natural keybindings

    cperl-indent-exp is normally bound to M-C-q , but is only useful after you've put the cursor in front of the block to highlight (here the for ), that's why I remapped it to work from inside the block.

    M-q should be the far better choice ( I hate 3+ finger combinations). In cperl-mode it's bound to cperl-fill-paragraph which wraps text to 80 colums ONLY in POD, here-docs or comments, but isn't useful in code! ( well as long as you are not trying to obfuscate )

    But now I'm not sure how to combine the old cperl-heuristic to distinguish between code and text with this new features, without patching cperl.

    Nice to have for my-indent-block
  • repeated manual calls should format ever bigger surrounding blocks till reaching the file-scope. (It's pretty easy to check the last command for repetition)
  • automatic delete-trailing-whitespace inside the block would be nice too (easy)
  • deleting unnecessary trailing empty lines at the block end
  • the cperl's indentation doesn't reformat spaces inside brackets or around operators (see print) yet
  • the cperl's indentation doesn't align = and => yet *
  • any other formating feature from perltidy I forgot



    *) there is align-current for regions, but it's reg-ex based fails with nested structures

    my $a = { a => 1, b => { c => 3, } };

    but with the semantic information of cperl's parsing it's possible to distinguish between the different levels of =>.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

A unit-test script that causes remorse
1 direct reply — Read more / Contribute
by Dallaylaen
on Sep 05, 2016 at 07:10

    Hello, dear esteemed monks!

    I have made a test script that makes cover -t include untested modules into the summary, thus lowering the overall coverage level and the developer's exaggerated ego.

    Not even sure how I didn't come up with something like that earlier. So... Here it is:


    UPDATE The script doesn't spawn more processes now and runs on Windows. No warnings issued.

    #!/usr/bin/env perl # This script tests nothing (except the fact that modules load w/o war +nings). # However, it tries to load them all. # This means that untested modules would also be included into # code coverage summary, lowering total coverage to its actual value. # I.e. having a well-covered module and a totally uncovered one will r +esult # in 50% coverage which is probably closer to truth. use strict; use warnings; use Test::More; use FindBin qw($Bin); use File::Basename qw(dirname); use File::Find; # Try to load EVERY module in t/../lib my $path = dirname($Bin)."/lib"; my @files; find (sub { /\.pm$/ or return; -f $File::Find::name or return; $File::Find::name =~ s#^\Q$path\E[/\\]##; push @files, $File::Find::name; }, $path); # Save warnings for later my @warn; foreach my $file (@files) { # This sub suppresses warnings but saves them for later display local $SIG{__WARN__} = sub { push @warn, "$file: $_[0]"; }; ok ( eval{ require $file }, "$file loaded" ) or diag "Error in $file: $@"; }; # print report foreach (@warn) { diag "WARN: $_"; }; # If you are concerned about cover -t, then probably warnings during l +oad # are not OK with you is( scalar @warn, 0, "No warnings during load" ); done_testing;

    Suggestions, improvements are welcome!

My appreciation for PerlMonks
1 direct reply — Read more / Contribute
by stevieb
on Aug 26, 2016 at 20:13

    I started my foray into Perl in ~2001 when I started my job as a network engineer at an ISP. I had never heard of Perl before that. The predecessor that I took over for had written (looking back) a really shitty, redundant "application" to do the management of clients in what some might say is Perl 4 code.

    I quickly realised that automating most of the sysadmin duties out of the way so I could engineer my core network peering via BGP was critical. I picked up a "Learn Perl in 21 Days" book off of a shelf, and practised everything in it. Two-arg open it had, and no mention of strict, my or anything. I mastered the simplicity of that book in about four days.

    I quickly grew fond of Perl, writing up scripts that automated basic things, as to rid myself of sysadmin duties so I could focus on what I loved; networking.

    Wasn't long before I found PerlMonks, and for eight years, I lingered around as an observer. Why I didn't join, I'll never know. Over time, I did start taking part in the newsgroups and email lists, then one day in 2009, I either saw a question that I could answer, or had a question... I can't remember. (I had been an active member in many other forums, particularly cisco-nsp, NANOG, and numerous FreeBSD lists).

    In retrospect, of course, I should have joined earlier, but I didn't. Not long after I joined was the whole hack fiasco. I stuck with it. I started answering questions that I could to give back. I absorbed the criticism given to me in my mistakes, which was crucially valuable in how I approach things today.

    Due to the people of PM, and the culture of PM itself, I believe that I am a more genuine person online, am willing to admit mistakes everywhere, willing to correct others (politely), and willing to apologize when I've been an asshole.

    To me, Perlmonks is a place where we can learn, have fun, get angry at each other, but at the end of the day, we're all here for one reason... to help the newb while helping each other.

    No matter how much one knows, there's always more to learn.

    Thanks to all those here (way too many valuable people to mention personally), the p5p team, the pumpking (SawyerX at time of writing, took over for Ricardo Signes in the not-so-distant past), Larry, and everyone else who has had any part in aiding and abetting the Perl community by answering questions, writing distributions, writing books (special shout out to merlyn) or just throwing their two cents in.



    ps. Back when, I'd claim myself as "not a programmer". Although I still am "not a programmer", looking back, the most memorable aspects of my technical career are the CPAN contributions I've made, and the work I've done to further the progress of Perl programmers, old and new.

    pss. This post isn't perl5 specific; love goes out to the perl6 crew all the same ;)

Why I won't be contributing to the 'CPAN rating system'; and why you don't want me to.
4 direct replies — Read more / Contribute
by BrowserUk
on Aug 08, 2016 at 03:38

    Here, because there is simply no point in burying this much effort and venom over there.

    if you applied your expertise while sticking to the technical issue at hand your input would be very valuable IMHO.

    Let's see, after 12 exchanges where I've politely tried to lay out all that is wrong with the "cpan rating" system: you want me to apply myself to what you think is a valuable cause. Correct?

    Don't be offended by the above, save that for later. This is just a reiteration of the reasons I will not be contributing to that system:

    1. It is obscure to the point of being almost invisible.

      I've been using cpan weekly, even daily -- it has been a pinned tab in my browser for nearly 13 years -- but whilst I'm sure I've noticed the stars, I've never taken any notice of them. See the next two sections for why.

    2. It is remote.
      • The ratings don't show up when looking at the module itself only in the search results list.

        When I'm viewing the documentation, I cannot compare how the reviews of a module have changed with its versions.

        If I review version 0.01 and give it a "bad review"; then the author takes that on board and corrects each and every concern I raise for version 0.02; what do I do? What does he do?

        Can I change my review? Can he change it? Does my review persist or die when he uploads a new version?

        If it persists; that unfair to good authors; if it dies, it is a license for bad authors to reversion often.

      • They have zero affect on what is shown to me.

        I still need to wade through every screen of results to discover if the "best" one is on the last screen.

      • I cannot utilise them to reorder, group or compare the results I get.

        I have to read the reviews and then try and make a value judgement about the veracity of other peoples value judgements...

    3. It is numerically & statistically useless.

      What does 4 1/2 stars mean?

      With a restaurant, 1 star means "they serve food that is probably edible"; "if you find yourself outside, starving and in a hurry; it probably won't poison you; but if you have time, cross the road"; "You'll probably not eat here twice".

      But what does it mean for a module? It exists? It installs? It loads? It runs? It produces the right results? It has a crap interface and useless documentation but if you can get past that it produces correct results very efficiently?

      If you cannot give a zero value, let alone a negative, 1 star (should; could logically only) mean: "I tried this module and the experience so incensed me that I actively came back to give it a negative review; but the worst I could do was give it 1 star".

      And 5 stars means either: "This module really saved my bacon" or "I'm the author upselling my own baby".

      And 3 stars should mean: Nothing! A module that "just works" doesn't engender enough emotion to be bothered to go back and post a review; but probably means: "I had enough problems with this module that I felt the need to say/do something; but I don't want to offend the author who has taken the time and effort to freely share his (crap) code".

    4. It is intellectually & morally questionable.

      That whole "hidden reviews" thing is suspect.

      If they are "mostly spam" why keep them around; simply delete them.

      However; if there is some other category(ies) of review that can be hidden (as implied by the word "mostly") what are those categories? Who decided them? Who decides which reviews fit into them? What checks & balances are in place to prevent authors; or their mates; or the "in crowd" or ... from abusing that mechanism to suppress reviews they disagree with; or by people they don't like?

    5. It is simultaneously both too complicated and too simplistic.

      Let's say I reviewed Moose and expressed my opinion that it is: too big; too slow: does the wrong thing; encourages the wrong thing; is impossible to debug; and creates a nightmare dependency chain that will be the perpetual predominant cost drain for any major project that uses it, once that project moves into maintenance; and gave it a 1 star rating.

      What effect would that have? Zilch!

      Without evidence; its just opinion. And let's just say I was incensed enough to work up data and provide evidence for all of those things; and I posted a 10 page treatise to explain all that; who would read it? No one!

      And the effect of my 1 star? If 19 produces an average of 4.5; then my 1 star would result in a value of 4.325. Would the star system reflect that? And if it did, would anyone notice? The answer to both is a resounding: NO!

      So what would be my incentive for expending the time and energy in producing such a review?

    Basically, not only are you asking me to not just express my opinion, but rather work up a technical discussion to support my position -- which is often as not based upon instinct rather than rigorous discovery(*); but to do so in support of a system that you feel has merit and which I feel has less than none.

    *example: if I look inside a module source and find the code "badly formatted"; I'm as likely as not to stop looking further.

    if you applied your expertise while sticking to the technical issue at hand your input would be very valuable IMHO.

    Okay. Here is where you -- along with many others -- are likely to be offended.

    I am not a member of a "Perl community"; I'm a Perl user. The only thing I have in common with other Perl users, is my use of Perl. THAT IS NOT THE BASIS FOR A COMMUNITY!

    I don't attend Perl conferences; I'm not a member of any Perl Monger's group; I don't "hang out" is #perl; I'm not a "member" of p5p; I don't have an account on; nor do I blog about Perl. (Nor anything else!)

    I consider "online communities" to be an oxymoron; the ultimate in naïve anthropomorphisation of technology.


    a group of people living in the same place or having a particular characteristic in common.
    the condition of sharing or having certain attitudes and interests in common.
    a group of interdependent plants or animals growing or living together in natural conditions or occupying a specified habitat.

    What I see of the Perl users is that they do not fit any of those criteria.

    The second is the nearest to something that one might apply to them if you squint hard enough; but it doesn't hold up to scrutiny.

    My affiliation with this site is purely selfish. I prefer to fill my down-time with stuff I find intellectually stimulating. For some its TV or music; for some video games; for some it crosswords or sudoku; for me, its programming. Historically, I came here to learn Perl for a particular purpose. That purpose evaporated, but despite that, Perl rapidly became my go to language for getting stuff done.

    I stayed because I found the ready supply of interesting problems stimulated me to becoming very intimately involved in understanding just what it is about Perl that makes it so productive. In a nutshell, I put that down to a combination of: intuitively minimalist design and pragmatic implementation.

    But as a whole, I find that the users of Perl are riven with internal conflicts. Less a group of like minded people brought together by their shared backgrounds, goals and aspirations; more a scrum of disparate people all pulling, tugging and warring, trying to bend Perl to what they think it ought to be. If you doubt this, read Re: What's the perl5's future?.

    So, besides that I won't lend my efforts to what I consider to be a wholly inadequate, broken and questionable system -- because I can see my reviews being routinely hidden thus wasted effort -- you can probably see that you (authors; the Perl community) almost certainly do not want me to do so.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Larry Wall on Slashdot
2 direct replies — Read more / Contribute
by perldigious
on Jul 18, 2016 at 15:59
use y
2 direct replies — Read more / Contribute
by shmem
on Jul 13, 2016 at 12:29

    No, I don't mean to use y instead of x, having an XY Problem. This is about a silly module - but a rather handy one.

    I'm presenting just the POD of it. I'm not posting the entire module because... see the COPYRIGHT AND LICENSE block. WARNING: insane code ahead.


    y - your own toolbox


    $ export PERL5LIB=$HOME/priv/lib $ perl -My=mail,A,:date,frob -le '...' Unimplemented at -e line 1.


    • x
    • eow
    • umble
    • imimi
    • ...


    The german version of this module is named The spanish and italian versions are proper.




    Copyright (C) by you.

    This library is concealed software; you should not redistribute it and/or coerce it on your coworkers under the same terms as Perl itself, neither Perl version 5.18.2 nor, at your option, any later version of Perl 5 you may have available.


    Is that copyright ok for you? Did I miss any important wrongdoing? Nonwithstanding the distribution of the whole module being discouraged, it is ok to post snippets that fit nicely into, e.g.

    my($m,$z); $m=pack"B32",pop=~'/'x$'; printf"$` network %vd broadcast %vd netmask %vd\n",($z=eval$`)&$m,$z|~ +$m,$m
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
[EMACS] "Emacs as Perl IDE" - Abstract for YAPC::EU 2016
6 direct replies — Read more / Contribute
by LanX
on Jul 09, 2016 at 12:33


    In the meantime the talk took place, here the links:

    Original Post

    Here the abstract for my talk proposal for Cluj

    ... not sure if it's too late to be still accepted

    Comments and corrections are welcome

    Emacs offers even more ways to do it than Perl's TIMTOWTDI .

    This demonstration will show how to combine some .el packages to create a neatly integrated and productive Perl development environment. (well from the authors perspective)

    Intended audience : Emacs users trying to navigate thru all these possibilities.

    After a short introduction into emacs (v24) for non-users we'll concentrate on builtin Perl support and how to add some other language agnostic projects to approach the author's IDE of what an IDE should look like.

    For starters: Overview of Emacs goodies (and some myth-busting)
    • open source
    • available on all development platforms
    • runs in windows and TTY
    • start-up time and memory consumption comparable to Vim ( != vi) just try emacs -nw -Q
    • package management for a huge universe of extensions
    • CUA shortcut emulations for "modern" applications (C-x C-v C-z C-a ...)
    • VIM command emulation evil-mode (includes text objects)
    • regional undo Undo only in selected text.
    Out-of-The-Box support

    What comes already builtin for Perl?

    ** cperl-mode

    The Standard mode for Perl features, including

    • imenu easy navigation for subs
    • auto indentation
    • code transformation prettifying regex convert postfix <-> prefix for "if" , "unless", etc
    • compile options
    • formatting options akin to perltidy
    • documentation display
    ** perldb

    Perl debugger integration, stepping through original file

    ** flymake-mode

    Interactive syntax check while typing by running "perl -c" in background

    ** dabbrev-mode

    avoid typos of identifiers by expanding from dynamic abbreviation dictionary

    Recommended Extension Packages

    ** Yasnippet

    Yasnippet (Yet Another Snippet Package) emulates the Textmate snippet features, which seem to become a standard now across all IDEs

    ** Auto Complete

    auto-complete.el shows completion alternatives in drop-down while typing from different sources (functions, variables, snippets,...)

    ** (Omni Complete)

    probably covered, this is a very promising project but yet not personally tested

    ** ECB = Emacs Code Browser

    The IDE "look an feel" with many specialized information panes to explore


    ** Regex-tool

    A tiny project to interactively test Perl-regexes against text an see the resulting matches.

    Demonstrates the extensibility of emacs.


    ** PIDE I - "Perl Integrated Development for Emacs"

    combining a stable set-up of Perl related el-modules and configs for a quick start with Emacs.

    ** PIDE II - "Perl Integrated Development for Every editor"

    Is an editor agnostic framework possible?

    Snippets and Completion-rules could be provided in POD "=for IDE" to support different projects like Moose or Mojolicious or whatever. A simple script could parse them on editor start-up and translate them to editor specific syntax.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Compiling Gtk+ stack on windows with strawberry perl
2 direct replies — Read more / Contribute
by frazap
on Jun 30, 2016 at 11:02

    I'm on Windows 10 with a perl 5.24 install in C:/strawberry

    I lost so many hours trying to understand why dmake always failed with undefined reference, that I thougt usefull to give a recipe to others when I finaly found a workaround. Here it goes:

    • download the latest (2.24) bundle for the Gtk+ stack from At the time of this writing (july 2016), the package installed using msys2 crashed on the tests with cairo so I return to the gnome ftp site.
    • unzip it in, say C:\prog, and rename the top folder to gtk+ so that you have a C:\prog\gtk+\lib folder that contains a lot of *.def, *.lib, *.dell, *.dell.a files
    • From the control panel use "System - Advanced system settings - Environment variables" to check or add if missing, the variable PKG_CONFIG_PATH in your user variables. Set it to C:prog\gtk+\lib\pkgconfig;C:\strawberry\c\lib\pkgconfig
    • add C:\prog\gtk+\bin to your PATH environment variable
    • from the cpan shell, download the following perl packages using the get command
      • Cairo
      • Glib
      • Pango
      • Gtk2
      The compilation and installation of these package will have to be done in the above order.
    • Each package is downloaded by cpan in C:\strawberry\cpan\build. To open a command shell in each of these folder, select the folder and while pressing the shift key, show the menu with the mouse right click, and select "open command window here".

      From the cpan shell, the command looks perl_module is another way to open a subshell in the corresponding build/module_folder

    • Edit C:\prog\gtk+\lib\pkgconfig\cairo.pc and replace the line having prefix=/devel/target/whatever with prefix=${pcfiledir}/../..

      Repeat this change for the files:

      gobject-2.0.pc pango.pc gtk+-2.0.pc
    • open a command shell in the Cairo-1.... folder
      • run the commands
        perl INC="-IC:/strawberry/c/include/freetype2 -IC:/prog/gt +k+/include/cairo -IC:/prog/gtk+/include/ -I. -I.\build"
      • Check that there is no "Warning (mostly harmless): No library found for ... ". Changing the prefix line in the pc file of the first library searched by allow perl to find all the external libraries.
      • Run
        dmake dmake test dmake install
    • Open a command shell in the cpan/build/Glib.... folder
      • run
      • perl INC="-IC:\prog\gtk+\include\glib-2.0 -IC:\prog\Gtk+\l +ib\glib-2.0\include -I. -I./build" dmake dmake test dmake install
      • On my pc, dmake test failed (tests in t/a.t all failled) but I installed Glib anyway.
    • Open a command shell in the cpan/build/Pango.... folder
      • run
      • perl INC="-IC:\prog\gtk+\include -IC:/prog/gtk+/include/f +reetype2 -IC:/prog/Gtk+/include/cairo -IC:\prog\Gtk+\include\Pango-1. +0 -IC:\prog\Gtk+\include\glib-2.0 -IC:\prog\Gtk+\lib\glib-2.0\include + -I. -I./build -IC:\strawberry\perl\site\lib\Glib\Install -IC:\strawb +erry\perl\site\lib\Cairo\Install" dmake dmake test dmake install
    • Open a command shell in the cpan/build/Gtk2-.... folder
      • run
      • perl INC="-IC:\strawberry\perl\site\lib\Glib\Install -IC:\ +strawberry\perl\site\lib\Pango\Install -IC:\strawberry\perl\site\lib\ +Cairo\Install -IC:\prog\gtk+\include -IC:\prog\Gtk+\include\glib-2.0 +-IC:\prog\gtk+\include\pango-1.0 -IC:\prog\Gtk+\include\cairo -IC:\pr +og\Gtk+\include\atk-1.0 -IC:\prog\gtk+\include\gdk-pixbuf-2.0 -IC:\pr +og\gtk+\include\gtk-2.0 -IC:\prog\gtk+\include\freetype2 -IC:\prog\Gt +k+\lib\glib-2.0\include -IC:\prog\Gtk+\lib\gtk-2.0\include -I. -I./bu +ild" dmake dmake test dmake install


    The command given above for perl Makefile.PL has been used for the gtk+-bundle_2.24.10

    A newer version could contains new libraries and this would cause dmake to fail with filex.h not found

    In that case, you have to add the path to the missing file with -Ic:/this/is/where/thatmissing/file/is in the INC arg given to Makefile.PL.

    Perl modules already installed have this header file in


    And external libraries to uninstalled perl modules have their header files somewhere in

    C:\prog\gtk+\include C:\prog\Gtk+\include\xxx C:\prog\Gtk+\lib\xxx\include
    So rerun
    perl Makefile.PL INC="changed to include the new path" dmake

    until dmake gives no error.

    The version of the Gtk2 perl module tested here were 1.2498 and 1.2499. If you try to compile these with an earlier version for the binaries (2.20 instead of 2.24) you will get undefined reference errors with GLib.

    Now if you change the path where your gtk+ libraries have been unzipped (or if you remove C:/prog/gtk+/bin from your PATH environment variable, your perl scripts using Gtk2 will crash.

    To gain independance from C:/prog/gtk+/bin, you need to copy some dll from this folder to your perl tree directory. This small script does this (the dll list hold for gtk+-bundle_2.24.10):

    use strict; use warnings; use File::Copy; my $from= "C:/prog/gtk+/bin/"; my %fm=('C:/strawberry/perl/site/lib/auto/Glib/' => [qw( libglib-2.0-0.dll intl.dll libgthread-2.0-0.dll libgobject-2.0-0.dll )], 'C:/strawberry/perl/site/lib/auto/Cairo/' => [ qw( libcairo-2.dll libexpat-1.dll freetype6.dll libpng14-14.dll libfontconfig-1.dll zlib1.dll )], 'C:/strawberry/perl/site/lib/auto/Pango/' => [qw( libgmodule-2.0-0.dll libpango-1.0-0.dll libpangocairo-1.0-0.dll libpangoft2-1.0-0.dll libpangowin32-1.0-0.dll )], 'C:/strawberry/perl/site/lib/auto/Gtk2/' => [ qw( libgtk-win32-2.0-0.dll libgio-2.0-0.dll libgdk_pixbuf-2.0-0.dll libatk-1.0-0.dll libgdk-win32-2.0-0.dll )]); foreach my $dest (keys %fm){ my $files = $fm{$dest}; foreach my $file (@$files){ print "will copy $from$file to $dest/$file\n"; copy("$from$file", "$dest/$file") or die("failed... : $!"); } }

    HTH !


PWM on raspberrypi with bcm2835
1 direct reply — Read more / Contribute
by martell
on Jun 25, 2016 at 13:14

    Dear Monks

    I thought I share this small Perl program demonstrating the possibility to do PWM (Pulse Wide Modulation) on Raspberry Pi in order to control the intensity of a led. This is a common introduction example to try for people learning about electronics on Raspberry Pi. Well documented examples for python exists, but not for Perl.

    The reason I share this here, is that the current CPAN module Device::BCM2835 doesn't define the necessary function to do this (that I see). So it took me some tinkering before I could control the PWM from Perl. Novice users of Perl may find this example code the thing they need.

    The solution I apply is the use of the Inline::C module to call some small wrapper functions I wrote in C around an existing C example I found on the internet. They call in turn the bcm2835 functions needed. This is tested on a raspberry pi B, revision 2 unit, using a single led and a single resistor.

    Be aware that on later versions of Raspberry Pi the GPIO pin layout is different and you have to use other constants in the functions calls in the C code. So YMMV, but enough documentation exists on the internet to figure out the correct values.

    This code assumes you have installed the Inline::C module, Time::HiRes module, and the bcm2835 C library on your device. See Device::BCM2835 module for the appropriate links to the C library. It is not installed by default. Run as root on Raspberry Pi because you need to have access to some low level functions.

    Today I'm not proficient in XSLoader to update the Device::BCM2835 module itself, but if I have some spare time, I will look into it. Would be a nice additional skill to master.

    Any thoughts or comments appreciated.


Azure remote desktop / Issues acessing network drives
1 direct reply — Read more / Contribute
by talexb
on Jun 23, 2016 at 10:10

    My work currently involves doing ETL (data-munging) using Perl. Because some of the data may have private information (PII), I'm doing my work on a remote desktop, which at this organization is Azure (Windows). It's not really my choice of platform -- but at least I'm able to use the excellent git-bash package to get (more or less) back to a Linux type command line.

    The issue I'm having is that transferring files from my volume to the volume where my output is carried on to the next step is unreliable, and I'm wondering if anyone else has come across the same challenge. I also want to check the existing files, as I append a version number to the end of my files so that new files don't overwrite existing files.

    • Copying files using File Explorer works, but sometimes a transfer will stall at 99%, at which point I may lose my connectivity to the remote desktop. That isn't a bad thing, although it irritatingly loses the network path in the destination folder, and I have to drill down through seven layers of directories to get back to where I was to check that my copy succeeded before disconnecting.
    • Copying via the command line (you knew that was coming next), while logical, also appears to be hilariously slow. A file that might get copied in 15-20 seconds using Explorer takes 15-20 minutes from the command line. I have no idea why, as it should be going from one network drive to another.

    The solution I've finally hit on (this is my work in progress) is to use chdir to go into the directory in question, and then glob to get a list of the files. It still takes ten seconds to get a list of files, but I guess that's the best I can do right now.

    Thoughts, comments, ideas are welcome. Thanks!

    Alex / talexb / Toronto

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

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 exploiting the Monastery: (5)
    As of 2016-10-22 16:29 GMT
    Find Nodes?
      Voting Booth?
      How many different varieties (color, size, etc) of socks do you have in your sock drawer?

      Results (297 votes). Check out past polls.