Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×
Programming

Journal Journal: Changing HTML::Element node attributes

I'm working with HTML::Element via HTML::TreeBuilder and its attractive look_down method. I am curious about changing the attributes of a tag for an HTML tree object.

Let's say I start at the root element 'hmtl', and I want to add a summary to the second table.

use LWP::Simple;

my $url = 'http://fire.org/';

my $content = get($url);

use HTML::TreeBuilder;

my $page_tree = HTML::TreeBuilder->new_from_content($content);

my @tables = $page_tree->look_down(_tag=>'table');

my $summary = 'make it for real';

The syntax for setting an attribute is:

$tables[1]->attr('sumary', 'Put your summary here');

The following syntax does NOT work

$tables[1]->attr('summary') = $summary;

Slashdot Top Deals

A computer without COBOL and Fortran is like a piece of chocolate cake without ketchup and mustard.

Working...