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: Compiling Gtk+ stack on windows with strawberry perl
1 direct reply — Read more / Contribute
by frazap
on Jun 30, 2016 at 11:02

    I'm on Windows 7 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 receipe to others when I finaly found a workaround. Here it goes:

    • download the latest bundle for the Gtk+ stack from http://ftp.gnome.org/pub/GNOME/binaries/win32/gtk+ 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 uses system - advanced system setting - environement variable to check or to add if missing, the variable PKG_CONFIG_PATH in your user variable and 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 with shift + mouse right click, 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/..... 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 Makefile.pl 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 Makefile.pl 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 Makefile.pl 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 Makefile.pl 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 Makefile.pl 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

    Notes:

    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

    C:\strawberry\perl\site\lib\xxxx\Install

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

    HTH !

    frazap

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.

    Martell

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.

Behavior of Flip-Flop Operators
1 direct reply — Read more / Contribute
by haukex
on May 29, 2016 at 11:09

    Hello everyone,

    A recent thread reminded me of a script I wrote years ago while learning about the flip-flop operator (aka the range operator in scalar context), and I thought I'd share it in case it helps someone else.

    The script, which I've included below the output, runs through a sequence of true/false values, tests whether the right-hand-side and/or left-hand-side of the operator is evaluated (marked by an asterisk in the table), gets the return value of the operator, and outputs all that in the following handy table. I hope it illustrates the difference between the .. (two-dot) and ... (three-dot) versions of the operator: two dots will immediately evaluate the RHS if the LHS is true, three dots will wait until the next evaluation.

    *** Demonstration of the Flip-Flop Operators *** __A______B____X___ __A______B____X___ 0* .. 0 = 0* ... 0 = 0* .. 1 = 0* ... 1 = 0* .. 0 = 0* ... 0 = 1* .. 0* = 1 1* ... 0 = 1 0 .. 0* = 2 0 ... 0* = 2 0 .. 0* = 3 0 ... 0* = 3 0 .. 1* = 4E0 0 ... 1* = 4E0 0* .. 0 = 0* ... 0 = 0* .. 0 = 0* ... 0 = 1* .. 1* = 1E0 1* ... 1 = 1 0* .. 0 = 0 ... 0* = 2 0* .. 0 = 0 ... 0* = 3 1* .. 0* = 1 1 ... 0* = 4 0 .. 0* = 2 0 ... 0* = 5 0 .. 1* = 3E0 0 ... 1* = 6E0 0* .. 1 = 0* ... 1 = 1* .. 1* = 1E0 1* ... 1 = 1 1* .. 0* = 1 1 ... 0* = 2 0 .. 0* = 2 0 ... 0* = 3 0 .. 1* = 3E0 0 ... 1* = 4E0 0* .. 0 = 0* ... 0 = 1* .. 1* = 1E0 1* ... 1 = 1 1* .. 1* = 1E0 1 ... 1* = 2E0 1* .. 1* = 1E0 1* ... 1 = 1 0* .. 0 = 0 ... 0* = 2 0* .. 1 = 0 ... 1* = 3E0 0* .. 0 = 0* ... 0 = (* = Evaluated)

    Regards,
    -- Hauke D

Evaluation Order again.
2 direct replies — Read more / Contribute
by BrowserUk
on May 27, 2016 at 20:13

    Back in 2005 I asked why the execution order of subexpression was undefined (in Perl; but it's inherited from C); and over a long and twisted thread I was shouted down by all-comers, accused of smoking waccy baccy etc. I don't think there was a single person that agreed with me that EO should be defined.

    12 years later and the C++ Evolution Working Group have finally caught up, and C++17 will probably get a defined order of subexpression evaluation.(pdf)

    Perl 6 could have stolen the march. Just sayin'.


    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.
-175 := +127 Thank you all! (Updated!Now -152 := +144)
6 direct replies — Read more / Contribute
by BrowserUk
on May 24, 2016 at 02:53

    Another 24 hrs on. The visible count of your downvotes since The significance of 2010-03-16? -- including the -18 on this post -- is now: -152(+23?). And my XP: +144(+17)! Thanks again :)

    In the 5 days since The significance of 2010-03-16? one hundred and seventy five of you have chosen to down vote one of my posts, (or 25 of you 7 of them; or ... ), for a total of -175(*) downvotes.

    (*Within the limitations of what the site architect permits me to discover.)

    The affect of that collective, heartfelt ire towards me, (or perhaps the subject matter), is that my XP has gone from 161809 on that day to 161936 this morning: +127.

    So, if the rating system is perfect; thank you all. And if its not; thank you anyway!


    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.
Persuading turkeys to vote for christmas
6 direct replies — Read more / Contribute
by BrowserUk
on May 19, 2016 at 19:44

    Tipping is a culturally dividing phenomena.

    In some parts of this world, paying some optional (but expected), discretionary (but socially narrowly defined) percentage of the bill for your food, to the house, for them to divvy up according to some (usually wholly inequitable) formula, between everyone front of house (and sometimes those in the back) -- often including those you feel do not warrant a tip -- in lieu of paying them a descent wage; is the $NORM.

    In other parts; tipping is a genuinely discretionary gratuity, paid by you to that or those persons you feel are deserving of it.

    The weird part is that most everyone in those former parts can see the inequities; but they blithely continue to perpetuate them anyway.


    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.
Mocking isa under Test::Deep
1 direct reply — Read more / Contribute
by choroba
on May 01, 2016 at 16:01
    At work, we use a rather old Perl on the servers (5.10.1 on RedHat 6, but still better than 5.8.3 at my $job-1), with similarly dated distributions. We plan to upgrade, so I tried running some of the tests locally on my laptop with Perl 5.18.2 (openSUSE Leap 42.1).

    Hash randomisation

    Most failures were caused by the new hash randomisation (see Hash order randomization is coming, are you ready?). As we use Test::Spec, most failures can be solved easily by turning an array reference into a bag:

    # Old: cmp_deeply($obj->method, [ $result1, $result2 ]); # New: cmp_deeply($obj->method, bag($result1, $result2));

    Mocking objects under Moose

    We use Moose in most of the code, which makes mocking a bit harder because of type constraints. Imagine you have the following code you need to test:

    use warnings; use strict; { package Person; use Moose; use namespace::autoclean; has name => ( is => 'rw', isa => 'Str', required => 1, ); has id => ( is => 'ro', isa => 'Str', required => 1, ); __PACKAGE__->meta->make_immutable; } { package Position; use Moose; use namespace::autoclean; has person => ( is => 'rw', isa => 'Person', ); has title => ( is => 'ro', isa => 'Str', ); __PACKAGE__->meta->make_immutable; }

    When testing the Position, we don't care about the details of the Person. We only want to stub an object with the needed methods implemented, which can even be none:

    use Test::Spec; describe 'position' => sub { it 'instantiates' => sub { my $person = stub(); my $position = 'Position'->new(person => $person); isa_ok($position, 'Position'); cmp_deeply([ $position->person ], bag($person)); }; };

    (The last line doesn't make much sense in this context, but imagine more complex objects. We need to use the bag function somewhere to show the problem.)

    This would work under plain OO, but it doesn't for us; Moose complains:

    Attribute (person) does not pass the type constraint because: Validati +on failed for 'Person' with value Test::Spec::Mocks::MockObject={ }

    The common trick to solve this, appearing all over the code base, has been to stub the isa method of the object to always return 1. Moose's got happy when checking the object type, and no one else has cared:

    my $person = stub( isa => 1 );

    But alas, this trick doesn't work in the newer Test::Deep. Here's the failure message:

    Found a special comparison in $data You can only use specials in the expects structure at /home/choroba/pe +rl5/lib/perl5/Test/Deep.pm line 346.

    Pretty informative, don't you think? It took me several hours to find the exact reason; the indicated line was changed in May 2011 in the following way:

    # Old: if (! $Expects and ref($d1) and UNIVERSAL::isa($d1, "Test::Deep::Cmp") +) # New: if (! $Expects and Scalar::Util::blessed($d1) and $d1->isa("Test::Deep +::Cmp"))

    So, returning 1 from the isa method now makes Test::Deep believe the stubbed object is its special construct that shouldn't appear on the left hand side of the comparison.

    To verify that's actually the problem, I tried to modify the isa in a more sophisticated way:

    my $person = stub( isa => sub { $_[1] !~ /Test/ } );

    and yes, it started to work again. Moose asks for Person , so isa returns 1, the testing framework asks for Test::Deep::Cmp and therefore gets 0.

    Final solution

    But it's an ugly hack. Some other modules might get confused by such a mocking, as they might check for other classes not containing Test , or, worse, we also have several classes whose namespace contains Test somewhere. So, I created a helper function

    sub mock_isa { my ($class) = @_; isa => sub { $_[1] eq $class } }

    which can be used as

    my $person = stub(mock_isa('Person'));

    Not as short as the original trick, but still easier than reimplementing the whole inheritance logic. What tricks do you use?

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Reversed .= operator
4 direct replies — Read more / Contribute
by 1nickt
on Apr 29, 2016 at 12:40

    Hi all,

    I'm sure we've all wished for a concatenation operator that would prepend a string to a string in the same way the .= operator appends.

    So why isn't there one?

    It's silly that you can write:

    $foo .= 'bar';
    But not:
    $baz =. 'qux';
    and instead have to do:
    $baz = 'qux' . $baz;

    Today I got to wondering if I had missed that such an operator had been introduced in some recent Perl version so I ran the code, and to my surprise Perl said:

    Reversed .= operator at -e line 5. syntax error at -e line 5, near "=."
    Now, if Perl knows that this particular syntax error is a "reversed .= operator", and not, say, "some new operator I didn't know about" - i.e. the syntax is not in use for anything else - then why isn't it implemented?

    Can any guts gurus shed any light?


    The way forward always starts with a minimal test.
Regular Expreso 2
2 direct replies — Read more / Contribute
by choroba
on Apr 26, 2016 at 16:24
    As you might have noticed, I like programming puzzles and brain teasers. But I hadn't participated in a real public contest... until today. I registered to Regular Expreso 2 on HackerRank. The participants had 24 hours to solve 8 tasks, Perl was among the supported languages. The contest was regular expression-centered, your code had to always end the same:
    $Test_String = <STDIN> ; if($Test_String =~ /$Regex_Pattern/){ print "true"; } else { print "false"; }

    The top 10 contestants (most points + shortest time) won a T-shirt. Once I realised there were more then 10 people with the full score, I knew I wasn't getting one, but I still wanted to get the full score.

    But I had no idea how to solve one of the tasks: the input was a long string of zeroes and ones. Your regex had to recognise whether the string encoded two binary numbers in the following way: when you reversed the string and extracted the odd digits, you got a number three times greater than the one built from the remaining digits. For example,

    1110110001 => 00111, 10101 7 21 3 * 7 = 21, accept!

    I wrote a short script to generate some examples, but I wasn't able to find the pattern. Moreover, the regex couldn't have more than 40 characters!

    Then I remembered Perl has a way to run code in a regex: the (?{...}) pattern. I read the relevant perlre section several times and tried something like the following:

    use bigint; sub check { my ($bin, $three) = ('0b') x 2; my $s = $_; while ($s) { $three .= chop $s; $bin .= chop $s; } return oct $three == 3 * oct $bin } $Regex_Pattern = qr/(?{ check() })/;

    The problem here is that (?{...}) always matches. Fortunately, you can use the code pattern as the condition in

    (?(condition)yes-pattern|no-pattern)

    As the yes-pattern, I used ^ which always matches, and (*FAIL) for the no-pattern:

    $Regex_Pattern = qr/^(?(?{ check() }) ^ | (*FAIL) )/x;

    The qr adds some characters, so to be sure I don't overflow, I renamed the subroutine to c and golfed the solution to

    '^(?(?{c()})^|(*F))'

    I got the full score! Would you call such a solution cheating? On one hand, I see that's not what the organisers wanted me to do, on the other hand, that's what Perl regular expressions give you. In fact, with the "start or fail" pattern, I can solve almost any problem with a regular expression!

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Good practice: A case for qr//
1 direct reply — Read more / Contribute
by LanX
on Apr 25, 2016 at 13:28
    Just wanted to share why using qr// to store regexes is usually a better idea than using strings...

    Today I was told to debug why a night batch failed to complete in the last weeks ...

    As it turned out filenames where checked with a list of hardcoded regexes and one of them had a typo. Instead of filter => ".*pl|.*txt" it had ".*pl|*.txt" which was hard to spot among many other regexes and caused a runtime error.

    Now using qr would have caused filter => qr/.*pl|*.txt/ to fail immediately at compile time.

    And since my colleagues use Komodo which runs perl -c at background (aka flymake-mode in emacs) this would have meant noticing the typo instantly while editing.

    HTH!

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

    PS: not wanna talk about the other flaws, like why extensions are checked with handcrafted regexes or why exitcodes from batches weren't checked...

Bullish on Moose, how about you?
7 direct replies — Read more / Contribute
by nysus
on Apr 22, 2016 at 16:44

    I've been a programming dabbler on an off for the past sixteen years or so (not counting the year I learned Apple Basic as a kid). I've recently gotten heavily back into programming for a couple of largish personal projects; most recently a event aggregator for the community where I live. For the last project, I decided to take a stab at doing OO Perl because too often I found that my procedural code for larger projects often degraded into spaghetti code as I dropped in more and more code to address all the edge cases that inevitably cropped up.

    Fortunately, I had worked some with "old school" OO Perl in the past, just to get familiar with it. I had also played a little with other OO-oriented languages so was pretty familiar with most of the concepts. Still, I had to dig out my worn copy Damian Conway's "Object Oriented Perl" book written back in 2000 to refresh myself. But after writing a fairly modest program with old school OO Perl, it became apparent that it's probably not practical for a less experienced programmer like me to use old school OO Perl for bigger, more complex projects like the event aggregator I was trying to build. I had to waste too much effort worrying about whether I was using Perl properly to implement OO design and grok all kinds of advanced programming techniques to make it all work.

    Then some Monks here recommended that I try Moose. I had never heard of Moose but, man, I am extremely glad I took their advice. Over the past month or so that I have been working with Moose, I found it to take a lot of the tedium out of programming and it has made it a much more joyful and less frustrating experience for me. When I see my code taking on the form of stringified pasta, I can easily break the code down into discrete chunks that makes it much easier for me to focus on the big picture of the program's structure and less on the detailed ins and outs of what the code is doing. I have a lot left to learn with Moose but there seems to be little question at this point in time that Moose will make me a better, more productive programmer and will help me create much more maintainable code. I can't see myself using anything but Moose for all but the simplest of scripts.

    I'm wondering if other Monks who have tried Moose have similar feelings as me. Maybe I was just horrible procedural programmer. Have you tried Moose and then abandoned it? Right now I don't see any downsides to using it (my scripts don't have to run fast), but I'd be interested to know if you have a different take on Moose. Are there any limitations inherent to Moose that I should be aware of?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Support for URLs with link titles in Pod::Html
1 direct reply — Read more / Contribute
by thomas895
on Apr 19, 2016 at 01:03

    Pod::Html, which ships with the core, breaks on things like

    L<PerlMonks|http://www.perlmonks.org/>

    ...with an error message like

    C:\STRAWB~1\perl\bin/pod2html.bat: ../test.pod: cannot resolve L<PerlM +onks|http://www.perlmonks.org/> in paragraph 6.

    This is not unique or new, as evidenced by hyperlinks in pod and others.

    I still use 5.12.3 (too lazy to reinstall all the modules I've accumulated), so I decided to patch the module so it does accept the URLs by putting together two other expressions.
    In v1.09 (the latest version of its kind), around line 1605, add this snippet after the if block:

    # some L<>'s that shouldn't be: # a) full-blown URL's are emitted as-is if( $par =~ m{^\w+://}s ){ return make_URL_href( $par ); } # --- add this: --- elsif( $par =~ m{^([^|]+)\|(\w+)://(.+)}s ) { #link text in $1, scheme in $2, everything else in $3 return sprintf '<a href="%s://%s">%s</a>', $2, $3, html_escape($1) +; }

    It might not work in all cases, but it seems to work for everything I could think of.

    Pod::Html was replaced with a Pod::Simple solution in v5.16.0 (as evidenced by perl5160delta), but if you use something older like I do, and you've run into this frustration, it might save you the bother of having to rewrite a bunch of code to use something else.

    Bonus: Make the output more XHTML compliant

    The output may say that it's XHTML-1.0 compliant, but this is not the case. One example that bothers XML parsers is that the <dt> tags aren't closed all the time. For example, when you have...

    =over 1 =item bla asdfghjk =back

    ... the resulting dt is closed as you would expect. But when you have...

    =over 1 =item sdfsfgsdh =back

    ...it just outputs a blank, unclosed dt tag (followed by a dd tag with the text in it, as expected). To fix this, change this part around line 1211:

    if ($text =~ /\A(.+)\Z/s ){ # should have text emit_item_tag( $otext, $text, 1 ); # write the definition term and close <dt> tag print HTML "</dt>\n"; }

    to this:

    if ($text =~ /\A(.+)\Z/s ){ # should have text emit_item_tag( $otext, $text, 1 ); } # write the definition term and close <dt> tag print HTML "</dt>\n";
    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."
developing in vim and tmux
4 direct replies — Read more / Contribute
by morgon
on Apr 17, 2016 at 19:09
    Sorry for slightly misusing this section as this is not something deep - just a little productivity hack...

    As a vim-user for many years I would edit my script in the one true editor and then run it (again and again for development) either in another terminal altogether or would background vim via Ctrl-Z.

    But now I have found something more convenient.

    If you run vim inside tmux and install the vimux-plugin you can send tmux-commands from within vim.

    Now add this to your .vimrc:

    let mapleader=" " map <Leader><space> :VimuxRunCommand("perl " . bufname('%'))
    If you now open your perl-script in vim within a tmux-session and hit <space> twice (tweak the key-binding to your liking), a new tmux-pane opens and runs your script - without loosing focus in vim - so much nicer...
When does programming become automatic (if ever)?
15 direct replies — Read more / Contribute
by nysus
on Apr 12, 2016 at 18:56

    We have all seen gifted programmers who seem to have an innate ability to code circles around others. These coders are like the 12 year old prodigies you see banging out Scott Joplin tunes on the piano like nothing. I'm sure there are many Monks blessed with this kind of skill.

    But leaving the gifted ones aside, how long does it take for the "normal" person to code fluently? By "fluently" I mean being able to code about as effortlessly as one types out prose in their native language into the keyboard. It means not having to think about the mundanities of grammar or spelling or syntax. Instead, you just let the ideas in your head flow kind of magically out from your brain and into your fingertips. It also means you know a lot of the basic tropes and idioms to express yourself in a clear, compact way without much effort. Maybe every once in a while you consult a dictionary or thesaurus but by and large you can bang out something relatively quickly without much struggle.

    As a programming hobbyist who has never worked alongside other programmers, I'm curious to know if this state is achieved by most professional programmers and what it takes to get there. Are we looking at 2 years of full-time programming? 5 years? 10? Or maybe programming is by nature an activity that starts and stops in fits and is never quite effortless? I'd be interested in hearing some experienced programmer's thoughts on this and what it took to get you to a blissful, effortless state of coding.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks


Add your Meditation
Title:
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.