21 May 2002 LotR   » (Master)

ianmacd seems to think Ruby's missing_method is a unique feature. I think it's more likely it was borrowed from Perl:

#!/usr/bin/perl

sub main::AUTOLOAD { my ($method, $data, %attrs) = ($AUTOLOAD, @_); my ($tag) = $method =~ /.*::(\w+)/g; my $attr_str; foreach my $key (keys %attrs) { $attr_str .= sprintf (" %s='%s'", $attrs{$key}); } return sprintf ("<%s%s>%s</%s>", $tag, $attr_str, $data, $tag); }

print &a ('Google', href => 'http://www.google.com'), "\n"; print &ul(&li('item1') . &li('item2') . &li('item3')), "\n";

Of course, TMTOWTDI, and ianmacd already mentions CGI.pm, which does the same thing, only more robustly.

Another module is quite useful if you want to edit your html tree at some point after creating it, HTML::Element. An example of how to create a tree with it, and print it:

use HTML::Element;

my $foo = HTML::Element->new_from_lol ( ['p', ['a', {href => 'http://www.google.com'}, 'Google' ], ['ul', map ['li', $_], qw(item1 item2 item3) ], ], );

print $foo->as_HTML;

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!