Hacks 1-11
Everyone wants to be more productive. That's probably why you use Perl: to get more work done in less time with less work.
Productivity isn't all about saving time, though. Saving effort is even more important, whether you mean finding the information you want, automating away repeated tasks, or finding ways not to have to think about things that you do all the time. In some ways, this is the notion of relentless automation—finding every little niggling task that always interrupts your current project by being so annoying, difficult, cumbersome, or different and then hiding it behind an alias, a shell script, a process, or whatever.
Here are a few ideas for ways to make your programming life easier and more productive. Try them, enjoy your new sense of free time, and let yourself notice the new points of friction in your life. Then solve them, too!
Keep module documentation and distributions mere keystrokes away.
If Perl has only one advantage over other programming languages, it's the number of modules on the CPAN (http://www.cpan.org/) that solve so many problems effectively. That brings up a smaller problem, though—choosing an appropriate module for the job.
http://search.cpan.org/ helps, but if you visit the site many times a day, the steps to start a search through the web interface can become annoying. Fortunately, the Mozilla family of web browsers, including Mozilla Firefox, let you set up shortcuts that make browsing much easier. These shortcuts are just bookmarked URLs with substitutable sections and keywords, but they're very powerful and useful—almost command-line aliases ("Make the Most of Shell Aliases" [Hack #4]) for your browser.
Here are three of the most useful.
The first technique is to find the module you want. Normally, you could visit the CPAN search site, type the appropriate words in the box, submit the form, and browse through the results. That's too much work though!
Open the bookmark menu in your browser; this is Bookmarks→Manage Bookmarks in Mozilla Firefox. Create a new bookmark. For name, put Search CPAN
and for Keyword enter cpan
. In the Location box, type:
http://search.cpan.org/search?mode=module;query=%s
Figure 1-1 shows the completed dialog box. Press OK, then go back to the browser. Clear the location bar, then type cpan
Acme
and hit Enter. This will take you immediately to the first page of search results for modules with Acme
in their names.
If you know exactly the name of the
module you want, it's more convenient to jump straight to information about that module. Create a new bookmark named Show
Module
Documentation
, with the keyword of cpod
and the location:
http://search.cpan.org/perldoc/%s
Press OK, then type cpod Test::Builder
and press Enter. You'll see the latest version of the Test::Builder
documentation.
Tip
This doesn't seem to work for POD-only modules, such as Test::Tutorial
. Also, beware that the case must match exactly.
Sometimes it's more valuable to find advice from other people about a module, especially when you may have uncovered a bug or something inexplicable in the documentation. The AnnoCPAN project (http://www.annocpan.org/) is a public site that allows users to annotate the documentation of any CPAN module. This is a good way to share your hard-won knowledge about a module with the world.
Create a new bookmark yet again, with a name of AnnoCPAN Module Documentation
and a keyword of apod
. Set the location to:
http://www.annocpan.org/?mode=search;field=Module;latest=1;name=%s
Save the bookmark, then type apod
GraphViz
in the browser's location bar and press Enter. Scroll down a few pages and you should see notes on various paragraphs of the documentation.
The keyword search feature of Firefox turns your browser's address bar into a command line. It's simple to write your own CGI script or mod_perl handler to add a new command to the browser—all it has to do is take a query string and return information. You could easily write code to implement a single command that aggregates different documentation sources (for example, you can search JavaScript and HTML and Perl documentation with a single query).
The URL of the bookmark can be a javascript:
URL that runs code in the browser. In essence you're creating a bookmarklet that you trigger on the command line. You could use JavaScript to open the search results in a new window or tab or search for the currently
selected text.
Get Perl Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.