• Devel::NYTProf is the hot new profiler in town

    Adam Kaplan has released a cool new profiling tool, Devel::NYTProf. It's apparently taken the formatting beauty of Devel::Cover, the code test coverage tool, and used it to identify hotspots in your code. The results are beautiful: Overview and module-level detail. There's also a report writer that provides CSV output and lets you create your own output in your own format.

    I ran into a divide-by-zero error that I patched in my local copy, but other than that the results seem good. I look forward to whatever other improvements come. I'm also glad it's been released with the support of the New York Times.

  • The worst way to shorten names

    Dropping vowels to shorten names is a terrible practice. Quick, someone give me an idea what $hdnchgdsp means, an Actual Variable from some Bad Code I'm working on today.

    It's not just variables names, either. Filenames often need to be shortened, but dropping vowels is not the way to do it. You're left with unpronounceable names that are annoying to type.

    The key to effective abbreviation is not removal of letters from the middle of the words, but from the end. Sometimes, it doesn't make sense to shorten a word at all, like "post". If you have a file that is supposed to "post audit transactions", call it "post-aud-trans" or "post-aud-trx", not "pst_adt_trns".

  • Perl Foundation needs new members

    The Perl Foundation needs new blood. Jim Brandt writes:

    Have you ever wanted to get involved in The Perl Foundation, but didn't know how? Well, now's your chance. I'm pleased to announce open self-nominations for the following TPF roles:

    You can follow the links above to read descriptions of each of the positions. If you think you're a good fit for one or more of them, send me an email at cbrandt at perlfoundation dot org. I'll then invite you to a dedicated wiki we have set up just for the election.

    Once you join the wiki, you'll set up a page to post all of your experience and answer the questions provided in each section above. The wiki is private, but you'll be able to see the other candidate pages, and they'll see yours.

    The deadline to get all of your information in is midnight next Tuesday, March 11. Our committees elect their members, so the Conferences Committee will be voting on the CC chair and the Steering Committee will vote on the chair and PR positions. After we have a chance to look over everyone's information, we vote and select our newest members.

    You only have a week, so don't wait too long. I look forward to hearing from you.

    Karen Pauley is stepping up to run for Steering Committee chair, so how about you? Maybe that's a spot you'd like to work on, or maybe public relations is more up your alley. This is your chance to help lead TPF lead Perl and Perl development.

    Astute followers of TPF will note that the PR spot is open, a spot that I once held. Yes, I am no longer doing PR for TPF. I've done that job for a while, and now I'm moving on to do other things, not least of which is this little news called perlbuzz.com.

  • Sign up to help with Summer Of Code

    Google's Summer Of Code is upon us again. The Perl community has had some problems in years past with lack of organization, and the SOC mentors seem determined to not let that happen this year. Eric Wilhelm posts:

    TPF needs volunteers to make summer of code happen this year. It sounds like the administrators got stretched too thin in 2005 and 2006, and we really didn't have ourselves together in 2007. So, I'm proposing a departmental structure under a TPF umbrella, which will localize the cat-herding effects within various large projects (so far, parrot and Catalyst appear to be on board with this.) I would like to demonstrate that we have our act together this year, so we need to get a solid pool of administrative volunteers and mentors together before the 8th.

    Eric says that they need a backup administrator, to minimize the reliance on a single person; department heads for p5p, "modules", etc; suggestions about department structure, and plenty of mentors.

    What does a mentor do?

    • Act as a point-of-accountability for google
      • keep tabs on your student
      • prod the student for updates
      • fill-out midterm and completion evaluation forms
    • Take the student under your wing
      • get them participating on mailing lists, irc
      • make sure they know where to go for help and resources
      • answer questions about the bugs in the social machine
    • Represent the community
    • Get a t-shirt

    If you'd like to help, or have ideas, contribute at one of these three pages:

  • Good Perl code is the best form of evangelism

    Here in the Perl echo chamber, there's a lot of talk about advocacy and getting people to use Perl and whether Perl is more popular in the job market than PHP, but I think most of that is just wind in sails. We talk and talk and talk but when it gets down to it, people don't use Perl because it's bigger in the job market, or because of a well-argued thread on Slashdot. People use Perl because the power of Perl makes their lives easier.

    Back on the 17th, I posted that Perl would be allowed in the Microsoft Scripting Games. Now, I'm no friend of the "scripting" moniker, but I was glad it was allowed in and thought maybe there would be some good visibility for the power of Perl.

    Then I saw the results.

    Event 2 in the competition was to read in a text file of comma-separated values of ice skating scores, drop the high & low scores from each skater, and show the top three skaters and their average scores. Trivial for Perl, right? The solution that Microsoft posted, however, was effectively a VBScript script translated to a Perl program (by their own admission).

    Here's the solution they posted.

    %dictionary = ();
    open (SkaterScores, "C:\Scripts\Skaters.txt");
    @arrSkaters = <SkaterScores>;
    close (SkaterScores);
    foreach $strSkater (@arrSkaters)
    $intTotal = 0;
    @arrScores = split(",",$strSkater);
    $strName = @arrScores[0];
    @arrScoresOnly = (@arrScores[1],@arrScores[2],
    @arrScoresOnly = sort({$a  $b} @arrScoresOnly);
    $intTotal = @arrScoresOnly[1] + @arrScoresOnly[2] +
    @arrScoresOnly[3] + @arrScoresOnly[4] +
    $dblAverage = $intTotal / 5;
    $dictionary{$strName} = $dblAverage;
    $i = 0;
    foreach (sort {$dictionary{$b}  $dictionary{$a} }
    keys %dictionary)
    print "$_, $dictionary{$_}n";
    if ($i == 3) {exit}

    Just dreadful. Among the atrocities: Stringing together list elements with plus signs to get a sum; Hardcoded array indexes; Hungarian notation prefixes of variables, in addition to the Perl sigils; breaking out of a loop after three records are shown, rather than starting with a list of the top three. It's just not good idiomatic Perl code.

    Perl's arrays and hashes are powerful, and underused here. Perl arrays are treated like C arrays.

    In a few minutes, I had put together the following program which is shorter and clearer because it takes advantages of Perl's strengths.

    use warnings;
    use strict;
    my %averages;
    open( my $SCORES, '<', 'c:/scripts/skaters.txt' )
    or die "Can't open score file: $!n";
    while ( <$SCORES> ) {
    my ($name,@scores) = split ',';
    @scores = sort @scores;
    # Drop high & low scores
    pop @scores;
    shift @scores;
    my $total;
    $total += $_ for @scores;
    $averages{$name} = $total/scalar @scores;
    close $SCORES;
    my @names_by_score =
    sort {$averages{$b}  $averages{$a}} keys %averages;
    for my $name ( @names_by_score[0..2] ) {
    print "$name: $averages{$name}n";

    (I'll admit I haven't tested it against their sample data because their sample data is only available in a self-extracting .EXE, which is a bummer for us non-Windows folks, no?)

    After I wrote my solution, I noticed that they have an Experts Page that includes links to solutions offered by Jan Dubois of ActiveState. No surprise, Jan's solution is exemplary Perl, and I'm glad that Microsoft provides it. My frothing subsided a bit after discovering this.

    Rather than arguing with non-Perl people about which language is better, let's show them. Even more, let's show the people who think that Perl is only a scripting language, only for web sites, or can't be deciphered that Perl will make their lives easier if they'd only open their Swiss Army knives beyond the first blade.