in reply to Rename html page titles

This code should get you started.

#!/usr/bin/perl -w use strict; use HTML::TokeParser::Simple; my $parser = HTML::TokeParser::Simple->new(\*DATA); my $new_title = 'Some title'; my $html = ''; while (defined (my $token = $parser->get_token)) { if ($token->is_start_tag('title')) { $html .= $token->as_is . $new_title; $token = $parser->get_tag('/title'); # advance to last title t +ag; } $html .= $token->as_is; } print $html; __DATA__ <html> <head> <title> This is a title </title> </head> <body> <p>This is the body</p> </body> </html>

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Re: Rename html page titles
by bradcathey (Prior) on Sep 03, 2003 at 21:42 UTC
    I've been cruising these forums long enough to spot a question that's going to get a reply of "use a module." merlyn beat me to it and Ovid actually showed it. As a writer of fairly utilitarian Perl code (simple forms processing and MySQL for dynamic pages) I'm a little nervous about all this module talk. Having said that, I'm using and loving HTML::Template and GD.

    If anyone has a suggestion of where to go to get/read more elementary stuff on the scary modules (Programming Perl is too scant--more on how to create them), and which ones do what and simple tutorials on how to use them, we module neophytes would stop posting questions about parsing HTML.

    As one still new to the monastery, I'm open.

    Thanks module-saavy monks!
      If anyone has a suggestion of where to go to get/read more elementary stuff on the scary modules (Programming Perl is too scant--more on how to create them), and which ones do what and simple tutorials on how to use them, we module neophytes would stop posting questions about parsing HTML.
      Well, I have over 150 suggestions for you. Use the search box at the bottom of any page there to narrow it down a bit to a particular topic area.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.