Perl Archives

qr/STRING/msixpodual or qr/STRING/mixuploads ?

I released perl 5.13.10 today. I might write more about that later. But one significant change in it is that Perl now has many more regex flags.

So I wrote a short one-off script to find out what words I cound construct from the flags.

Now it just gives you one word that contains as many of the flags as possible, and gives you the remainder. What would be more interesting would be to detect cases where multiple valid words can be made from the flags. E.g. "mix" and "uploads". It just detected that by accident.

I leave that as an exercise for the reader.

Let's add Git userdiff defaults for Perl and Perl 6

Git allows you to define a custom hunk-header which'll be used by git diff as the context line in diff hunks. Git includes presets for several languages but no presets for Perl and Perl 6. I'd like to change that.

If you have no idea what these are, consider a file that contains this code:

sub foo {
    my $x = "a";
    my $y = "b";
    my $z = "c";
    my $poem = <<"POEM";
This is a
Long string
In a heredoc

Now, if you change the last statement in that subroutine to something more clever and run git diff you'll get this:

diff --git a/ b/
index 7ed4207..ffb1ff9 100644
--- a/
+++ b/
@@ -7,5 +7,5 @@ This is a
 Long string
 In a heredoc
-    I'm::On::A::Horse();
+    The::Tickets::Are::Now::Diamonds();

In that diff this is the context line:

@@ -7,5 +7,5 @@ This is a

Having "This is a" there doesn't provide very useful context, but that can be changed with userdiff, just add this to .gitattributes:

*.pl diff=perl

And this to .git/config:

[diff "perl"]
      xfuncname = "^\\s*(sub.*)"

And the hunk context is now more useful, and shows the name of the subroutine that's being changed:

@@ -7,5 +7,5 @@ sub foo {

I'd like to extend the Git defaults to include Perl, but I'm probably forgetting some cases where something is subroutine-ish that doesn't match simply "\\s*(sub.*)". Other cases I can think of are:

  • The package statement
  • my $x = sub { ... } (needs a complex regex to match `my/our ...)
  • The BEGIN/INIT/END etc. routines
  • Maybe "method ..." from MooseX::Declare and friends? It shouldn't hurt to include this
  • Something else?

Then there's the issue of Perl 6. I'm completely unfamiliar with it, but I can add it while I'm at it if I'm given some examples.

The userdiff facility also has support for defining a "word" for the --word-diff option to git diff. I don't use this option, but I wouldn't be surprised if it did the wrong thing for Perl code.

About Ævar Arnfjörð Bjarmason

user-pic Blogging about anything Perl-related I get up to.