• Higher-level list utility functions with List::UtilsBy

    I’m in love with List::UtilsBy. It’s one of those “Why didn’t someone do this earlier?” modules (or maybe it’s “Why didn’t I know about it earlier?”). It replicates much of the functionality of List::Util and lets them operate on arbitrary blocks.

    Read on →

  • All about the new Test2 framework and how it will help your tests

    The new Test2 framework has been released after a couple years of development. I wanted to find out about what this means for users of Test::Simple and Test::More, so I chatted with the project leader, Chad Granum (exodist).

    Read on →

  • Template Toolkit's DEFAULT directive does not short-circuit

    Template Toolkit’s DEFAULT does not do short-circuit evaluation like you might think it would. If you have

    Read on →

  • ack 2.0 has been released

    ack 2.0 has been released. ack is a grep-like search tool that has been optimized for searching large heterogeneous trees of source code.

    ack has been around since 2005. Since then it has become very popular and is packaged by all the major Linux distributions. It is cross-platform and pure Perl, so will run on Windows easily. See the "Why ack?" page for the top ten reasons, and dozens of testimonials.

    ack 2.0 has many changes from 1.x, but here are four big differences and features that long-time ack 1.x users should be aware of.

    • By default all text files are searched, not just files with types that ack recognizes. If you prefer the old ack 1.x behavior of only searching files that ack recognizes, you can use the -k/--known-types option.
    • There is a much more flexible type identification system available. You can specify a file type based on extension (.rb for Ruby), filename (Rakefile is a Ruby file), first line matching a regex (Matching /#!.+ruby/ is a Ruby file) or regex match on the filename itself.
    • Greater support for ackrc files. You can have a system-wide ackrc at /etc/ackrc, a user-specific ackrc in ~/.ackrc, and ackrc files local to your projects.
    • The -x argument tells ack to read the list of files to search from stdin, much like xargs. This lets you do things like git ls | ack -x foo and ack will search every file in the git repository, and only those files that appear in the repository.

    On the horizon, we see creating a framework that will let authors create ack plugins in Perl to allow flexibility. You might create a plugin that allows searching through zip files, or reading text from an Excel spreadsheet, or a web page.

    ack has always thrived on numerous contributions from the ack community, but I especially want to single out Rob Hoelz for his work over the past year or two. If it were not for Rob, ack 2.0 might never have seen the light of day, and for that I am grateful.

    A final note: In the past, ack's home page was betterthangrep.com. With the release of ack 2.0, I've changed to beyondgrep.com. "Beyond" feels less adversarial than "better than", and implies moving forward as well as upward. beyondgrep.com also includes a page of other tools that go beyond the capabilities of grep when searching source code.

    For long time ack users, I hope you enjoy ack 2.0 and that it makes your programming life easier and more enjoyable. If you've never used ack, give it a try.

  • Debunking the "five weekends every 823 years" myth with Perl

    Have you seen this bit of bunk posted recently? It goes like this:

    This year, July has five Fridays, five Saturdays and five Sundays. This happens once every 823 years. So: copy to your status and money will arrive within 4 days... based on Chinese Feng Shui.

    Of course it's crap, and of course Snopes.com does a fine job of debunking it. But what if you want more evidence? Perl to the rescue! Here's a little program that finds and counts all the months with five full Fri-Sun weekends in the next 823 years.

    #!/usr/bin/perl
    # Debunking the five weekends myth
    # http://www.snopes.com/inboxer/trivia/fivedays.asp
    use strict;
    use warnings;
    use feature 'say';
    use DateTime;
    my $start = 2013;
    my $end   = $start + 823 - 1;
    say "Months with five full weekends between $start and $end";
    my $nmonths = 0;
    for my $year ( $start .. $end ) {
    for my $month ( 1..12 ) {
    my $eom = DateTime->last_day_of_month(
    year => $year, month => $month );
    if ( $eom->day == 31 && $eom->day_of_week == 7 ) {
    say $eom->month_name, ' ', $year;
    ++$nmonths;
    }
    }
    }
    say "There will be $nmonths months with five full
    weekends in the 823 years between $start and $end.";
    $ ./five-weekends
    Months with five full weekends between 2013 and 2835
    March 2013
    August 2014
    May 2015
    ...
    October 2832
    July 2833
    December 2834
    There will be 823 months with five full weekends in the
    823 years between 2013 and 2835.