OSCON: Perl Hacks you Never Knew Existed

Here’s a brief summary of some of the “Perl Hacks” session I attended, presented by chromatic. The material was largely taken from the Perl Hacks book.

perldoc Hacks

Make perldoc case insensitive; add to your environment:

PERLDOC=-i

So you can then say…

$ perldoc cgi

Display the code of a module:

$ perldoc -m Some::Module

Show the location of a module:

$ perldoc -l Some::Module

You can also open it in your editor…

$ $EDITOR `perldoc -l Some::Module`

@INC Hack

Did you know you can put a coderef in the @INC array?

BEGIN { unshift @INC, \&some_subroutine }

sub some_subroutine {
    my ($some_sub_ref, $pathy_module_name) = @_;
    return unless can_handle_request( $pathy_module_name );
    return make_fh( $pathy_module_name );
}

To resolve a request, return the file handle to the located module. To let perl keep looking for the module, return undef.

Other, questionable things…

chromatic went on to describe how he can use Perl subroutine attributes to automatically set a ‘self’ routine in the current package (or even deparse the Perl code adding, a $self lexical then replacing the routine with the amended version). It frankly left me a little queasy, so I won’t describe it any further. Subroutine and variable attributes are indeed cool though.

TrackBack

TrackBack URL for this entry:
http://bradchoate.com/mt/feedback/tb/1372

About

This article was published on July 28, 2006 3:57 PM.

The article previously posted was OSCON: Extreme Perl Makeover.

The next article is utime.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type