• Getting lines from a website with GET and ack

    Oh no, hourly smoke test failures in my inbox today! Looks like I put some bad HTML on work's website's home page, and every hour one of the automated tests, via Test::HTML::Lint, told me once an hour that

    # HTML::Lint errors for http://devserver.example.com/
    #  (72:53) <a> at (61:53) is never closed
    

    Well, phooey, it's a PHP-driven website, so I can't open index.php and check lines 72 and 61. I can use GET, installed with LWP, to fetch the website and save the source:

    $ GET http://devserver.example.com/ > foo.html
    $ vim foo.html +61
    

    but since I'm a Perl programmer, I want to be as lazy as possible by using the tools at my disposal. In this case, it's ack, and ack has the --line option to display ranges of lines instead of results of a regex. (Thanks to Torsten Blix for implementing this!)

    $ GET http://devserver.example.com/ | ack --lines=61-72
    

    So much nicer that way! and look at it in an editor, but how much easier to not have to do that.

  • Put your work under version control today

    There is no project so small, so trivial, that it is not worth you putting it into a Subversion repository. If it's worth your time to work on it, it's worth saving. Putting it in Subversion is a matter of a few statements, and you don't have to do any big fancy-shmancy server setup.

    Let's assume you're working on Linux/Unix, and you have svn installed, which is pretty standard these days. Say you're working on a game called bongo, and you've just been keeping it in ~/bongo. Do this:

    # Create the Subversion repo
    $ mkdir /svn
    # Create the bongo repo
    $ svnadmin create /svn/bongo
    # Import bongo into its project
    $ cd ~/bongo
    $ svn import file:///svn/bongo -m'First import of bongo into Subversion'
    # Move the original bongo directory out of the way,
    # in case something goes wrong
    $ mv ~/bongo ~/bongo-original
    # Check out bongo from Subversion
    svn co file:///svn/bongo
    

    At this point, you'll have a checked-out version of bongo in ~/bongo, and you can make commits against it.

    Ricardo Signes points out that Git makes it even easier.

    # Go to the bongo directory
    $ cd ~/bongo
    # Import bongo
    $ git init
    

    With Git, everything is put in your ~/.git directory, and you don't have to check out anything from the project.

    Whatever route you choose, version control is so simple these days there's just no excuse not to do it. Your programming life will never be the same.

  • Show me the output before I install it!

    When you're releasing a module, please show a sample use or the output somewhere in the documentation so that people like me who are interested in your module can have some idea of what it looks like and how I'd use it.

    I take for example this new distro, pfacter, which purports to "Collect and display facts about the system." Sounds great, but how do I use it? I see a little program. Can I see some sample output? Please? There's nothing in the README or any kind of synopsis that shows it.

    Of course, I don't mean to pick on this one distro. It's just the one that disappointed me just now and made me post this. It's something that has always frustrated me, especially as I try to find cool new modules to mention here or over in Mechanix.

    (No need to point out that I haven't do this for ack myself. It's on my todo. :-) )

  • The relationship between a language and its toolchain, and why Perl 6 scares the hell out of Adam Kennedy

    Adam Kennedy has written a very thoughtful article on problems he sees coming up in Perl 6 called "The relationship between a language and its toolchain, and why Perl 6 scares the hell out of me." It's well worth reading even if you're not following Perl 6 that much.

  • Huge week on perl5-porters

    I'm amazed at how David Landgren manages to summarize the p5p traffic, especially this week. Last week's summary is 19K of text covering everything from what happens when you bit shift infinity, to what features people want in Perl 5.12, to outdated Test::Harness components.

  • Fluent numbers with Acme::Numbers

    Inspired by a post in the Beautiful Code blog, Simon Wistow created Acme::Numbers, which lets you do cleverness like this:

    use Acme::Numbers;
    print two.hundred."n";               # prints 200
    print forty.two."n";                 # prints 42
    print zero.point.zero.five."n";      # prints 0.05
    print four.pounds.fifty.five."n";    # prints "4.55"
    print four.pounds.fifty.pence."n";   # prints "4.50"
    print four.dollars.fifty.cents."n";  # prints "4.55"
    

    You probably wouldn't want to do this in production code, but like the best of Damian Conway's not-useful-but-thought-provoking modules, it may spark some ideas that you can apply to more useful situations. If nothing else, the source is a fine lesson in overloading and method importing.

  • The future of Strawberry Perl

    Adam Kennedy is thinking about the future of Strawberry Perl.

    In line with my attitude that the main Strawberry "product" should be conservative, reliable and predictable (I'm going with a rough analogy to Firefox product-wise) I've been thinking a little about how the release tempo should look. My current thinking for Strawberry Perl is to do quarterly releases, with a tentative schedule of releases in January/April/July/October and aiming at being available for download before the second Monday of the month.

    In addition, he's asking for your ideas on features to include in the April 2008 release.

  • Your favorite language sucks

    The other day I posted a link to an article by Ted Neward called "Can Dynamic Languages Scale?" I thought it was interesting to see that an outsider saw the potential in Parrot, even though it's not at 1.0 yet. As an afterthought, I lamented that he made a dig at Perl at the end, smiley face or not. I meant it to have the same sort of gravity as saying "Aw, shoot, it's raining out." I didn't care that he didn't like Perl, but that he had to take a swipe. It certainly wasn't a big deal.

    Apparently his article caused a minor uproar. Neward posted a followup called "So I Don't Like Perl. Sue Me" in response to the Perl folks arguing with his taste in languages. He shouldn't have had to do that.

    your-favorite-band-sucks.jpg I don't get Radiohead. It's all ponderous and aimless. I also don't get Phish, Peter Gabriel and/or Genesis, Yo La Tengo or Tori Amos. But so what? It's personal taste. I don't like Java, either, although I haven't written any in the past 10 years. You know why I don't like Java? It just doesn't look like it's any fun. I'm sure people can explain to me why Java is great, but it won't change my mind. And it doesn't need to.

    If you really want someone to love Perl, you'll have to show him, not tell him. Show him great code, great projects. Show the doubters that Perl can do amazing things. Action, not words. And if he still doesn't get it, that's OK.

  • Can dynamic languages scale?

    Ted Neward has written an article on the problems of scaling up projects based on dynamic languages:

    While a dynamic language will usually take some kind of performance and memory hit when running on top of VMs that were designed for statically-typed languages, work on the DLR and the MLVM, as well as enhancements to the underlying platform that will be more beneficial to these dynamic language scenarios, will reduce that. Parrot may change that in time, but right now it sits at a 0.5 release and doesn't seem to be making huge inroads into reaching a 1.0 release that will be attractive to anyone outside of the "bleeding-edge" crowd.

    Alas, he has to end with "Perl just sucks, period." Even as we work forward with Parrot and Perl 6, the continued public perception of Perl doesn't change. :-(

  • Vim tricks for Perl

    This thread on use.perl.org points to some cool vim support for Perl. I'm not sure I like all the doodads in perl-support.vim, but I did add this to my .vimrc:

    autocmd FileType perl :noremap K :!perldoc <cword>
    <bar><bar> perldoc -f <cword><cr>

    Now hitting K in vim runs perldoc or perldoc -f on the word under the cursor.

  • The man who couldn't refactor

    For the past few months, I've been slogging through some PHP code written by a solo programmer with no real oversight from other programmers. His code is a monoculture.

    I found this bit of code today that just sums up his unwillingness, or perhaps inability, to refactor.

    if (substr($libtest,0,12) == "FOO COUNTY")
    $foocounty=$getmultiples=1;
    if ((substr($libtest,0,12) == "FOO COUNTY") && ($state=="TX")) {
    $foocounty=$getmultiples=0;
    $foocountytx=$getmultiples=1;
    }
    

    Just read those lines of code and you can recreate the crime in your head. First there was a customer in Foo County. Then, we had to handle a different Foo County, but this Foo County was in Texas. He couldn't even be bothered to change the initial test to be more specific, or to modify the existing code. His solution was the simplest thing that could possibly work, and was also the worst: Reversing the effect of the first check for Foo County. There's also no checking for non-Texas, non-original Foo County, but when I checked I found that we have customers that are in Foo County in THREE different states.

    The programmer no longer works for us, so I'm unable to ask him about his motivations. I'm fascinated by the mindset that is unable to do the barest rework necessary.

  • Make your own mini CPAN

    Ricardo Signes' marvelous module CPAN::Mini just got an update today, and it reminds me to tell you all how great it is to be able to have a small version of the CPAN on your local hard drive, especially on a laptop. The included minicpan program makes it trivial to update your local archive.

    First, I make a little ~/.minicpanrc that looks like this:

    local: ~/minicpan/
    remote: http://cpan.pair.com/pub/CPAN/
    also_mirror: indices/ls-lR.gz
    

    And then I run minicpan every so often. This pulls in the latest version of each distribution, and deletes ones that are obsoleted by newer versions. When I run minicpan, it looks like this:

    $ minicpan
    authors/01mailrc.txt.gz ... updated
    modules/02packages.details.txt.gz ... updated
    modules/03modlist.data.gz ... updated
    mkdir /tmp/Woq_DHsWsN/indices
    indices/ls-lR.gz ... updated
    indices/ls-lR.gz ... updated
    mkdir /home/andy/minicpan/authors/id/G/GR/GROMMIER
    authors/id/G/GR/GROMMIER/Text-Editor-Easy-0.01.tar.gz ... updated
    authors/id/G/GR/GROMMIER/CHECKSUMS ... updated
    mkdir /home/andy/minicpan/authors/id/Z/ZO/ZOFFIX
    authors/id/Z/ZO/ZOFFIX/Acme-BabyEater-0.01.tar.gz ... updated
    authors/id/Z/ZO/ZOFFIX/CHECKSUMS ... updated
    ...
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEROSS/DBIx-StORM-0.04.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/Test-WWW-Selenium-1.13.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/mocked-0.07.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LO/LOCATION/Geo-IP2Location-2.00.tar.gz ...done
    cleaning /home/andy/minicpan/authors/id/L/LO/LODIN/Regexp-Exhaustive-0.03.tar.gz ...done
    

    Currently the repository is only 846M of disk space. Who doesn't have an extra gig lying around these days?

    uniqua:~/minicpan $ du -sh
    846M    .
    

    I also point my CPAN shell configuration to use the mini CPAN as its source of modules by prepending file:///home/andy/minicpan to the list of URLs it checks.

    Thanks to Ricardo for putting out this great tool, and Randal Schwartz for the original column on which it was based.

  • More vim goodies for Perl 5.10

    Rafael Garcia-Suarez has posted his modifications for vim to support Perl 5.10. His are a good deal more complete than the simple modification I posted last month that just covers the say keyword.

  • Take a nibble of Perl 6 with a microarticle

    If Perl 6 is a little daunting, take a smaller bite by reading one of Adriano Ferreira's Perl 6 microarticles. The index of articles is on the official Perl 6 wiki on the page called Perl 6 microarticles. As of now the list of articles is:

    For more news of Perl 6 and Parrot, please keep an eye on rakudo.org.

  • Designing too far into the future

    Max Kanat-Alexander has a new blog up called Code Simplicity, and I'd love it for the name alone. His latest post, "Designing Too Far Into The Future", talks about the perils of trying to predict the future and guess what your code will have to do down the road. In the XP world, the term that gets thrown around is YAGNI, for "Ya Ain't Gonna Need It." When you have to write a report and you start by writing a report generator, that's a big violation of the principle of YAGNI.

  • OSCON 2008 Call For Participation is now open

    Peter Scott sent in this call for participation for OSCON 2008.

    O'Reilly Media has announced their Open Source Conference Call for Participation. OSCON, which started as The Perl Conference in 1997, hosts the 12th annual Perl Conference this year. The OSCON Perl track review committee invites presenters to submit proposals for talks about the great things they've been doing with Perl. Make their job hard!

    This will be the breakout year for Perl 6 (maybe this is the Christmas???), and we will feature it at OSCON. We don't assume that we already know everyone who's got a Perl 6 talk for us; if you've got something interesting to tell people about Perl 6, submit a proposal.

    We are equally interested in Perl 5 presentations. This has been an exciting year for Perl 5: the Perl 5 Porters released Perl 5.10; perlbuzz readers recently heard all about Strawberry Perl; and Moose, a new object system for Perl 5, is gaining in popularity. We continue to hear stories about how Perl has saved jobs and money, and made work fun. Let's see your presentations on enterprise-scale Perl applications and infrastructure, and the coolest modules, hacks, and techniques for using Perl for Stuff That Matters.

    There's something special about the Perl community, and you can see it at OSCON thanks in no small part to the excellent presenters who turn out for it each year... so join them in 2008! See http://en.oreilly.com/oscon2008/public/cfp/13 for essential advice on submitting your proposal. The deadline is February 4, so start working on those proposals now!

    Peter Scott wrote Perl Medic and Perl Debugged and is a Perl trainer. He's presented at the Perl Whirl, YAPC, and OSCON, for which this year he is on the Perl track review committee.

  • How to: Create database columns that contain only digits

    I see this missed so many times I have to bring it up here: "If you have a database column that contains only digits, but will not perform calculations on it, make it a character column."

    You CAN store a 10-digit phone number as an integer, but why would you want to? You CAN store a Social Security Number as a 9-digit number, but why would you want to? Surely you're not so concerned of a few bytes savings. Storing an SSN of "0123456789" as a number means you use the leading zero, too, so you lose fidelity of data. Any string of digits follows this rule. You don't perform calculations on part numbers, course numbers, Dewey Decimal numbers, or house numbers, either, so make 'em all character fields.

    Same goes for years stored as date datatypes. If you're recording the year that a movie was released, then there's no advantage to having it as a date. Store it as an integer to make it simple to take differences ("How long after Citizen Kane did ET come out?") or comparisons.

    Most of all, keep things consistent. If you've got a 10-character column in one table, and an integer in another, then SQL joins will be very expensive, even if both columns are indexed.

  • Help the Perl Foundation choose a CRM system

    Jim Brandt, Conferences chair for The Perl Foundation, is looking for a customer relationship management package.

    I'd really like to deploy a customer relationship management (CRM) package to allow us to better track our relationships with our donors, big and small. I was a bit surprised to turn up next to nothing when I typed "perl CRM" into Google.

    Can you help? Read more of the story and reply at the TPF news blog.

  • Which language to inflict on clients?


    IMG_0616.JPG
    Originally uploaded by reedwade

    Brenda Wallace posted a colleague's picture of a whiteboard from their office today. Her post says "dunno which technology to inflict on my clients next, so we had a brainstorm. looks like TCL won."

    The whiteboard reads:

    Lisp is bitter
    PHP is DancingBear
    Python is beige
    Erlang is imaginary
    Ruby is a fad
    Java is angry
    Tcl is cute
    Perl is ready for retirement

    Certainly I don't think Perl is ready for retirement, but it's interesting to see what people think about Perl, and about all its brethren.

  • Strawberry Perl is all-inclusive

    Yesterday's article about Strawberry Perl referred to a blog post with incorrect installation instructions. All the downloading and installing discussed is just not necessary, even for CPAN installations. According to Adam Kennedy:

    The install and setup process for Strawberry Perl is to uninstall any existing Perl, run the installer, and then run "cpan" or run it from the Start menu. There is no additional installation required.