October 27, 2002

You think that's easy in Ruby? Try it in Perl...

In response to Cedric's good-natured Perl mocking, I offer this implementation:

package SimpleHTML;
use strict;
use vars qw( $AUTOLOAD );
sub new {
    my ( $class ) = @_;
    return bless( {}, $class );
}
sub AUTOLOAD {
    my ( $self, @msg ) = @_;
    my $request = lc $AUTOLOAD;
    $request =~ s/.*://;
    return "<$request>", @msg, "</$request>";
}
1;

And this sample usage:

#!/usr/bin/perl
use strict;
use SimpleHTML;
my $html = SimpleHTML->new();
print $html->body( "So long and thanks for all the fish" );

Result:

<body>So long and thanks for all the fish</body>

Easy, eh? :-)

Next: Personal space violation
Previous: Googlisms