Hi Todd

You could try something like this;

  while (my $htmlfile = glob "*.html") { # finds all .html files, and
                                # performs the substitution on each of them

    local $/ = undef; # slurp in the whole file in one go. Not generally
                        # recommended, but should be OK in this case since 
                        # HTML files are generally not too big. Use it to
                        # make life easier with newlines etc.

    my $substitute = qq!<link rel="stylesheet" href="glob_style.css"
type="text/css">\n</title>!; # This is the text we're going to put in

    open IN, $htmlfile;
    my $html = <IN>; # put the file into scalar $html
    $html =~ s!</title>/$substitute/; # I agree with Akshay that you're 
                        # probably better off just looking for </title>. If
                        # your headers are as you say, it will make no 
                        # difference anyway.

    rename $html, $html.".old"; # Keep a backup of the old html file

    open OUT, $htmlfile;
    print OUT $html; # Write out the new version of the file
  }

I hope this should work. Needless to say it's untested, so please make a
backup first 8-)

Cheers

Mark C

> -----Original Message-----
> From: todd [mailto:[EMAIL PROTECTED]]
> Sent: 23 July 2001 23:54
> To: Perl Discuss
> Subject: search and replace
> 
> 
> I have a bunch of .html files that I want to add a style sheet to.
> currently, the top of the html file has this:
> 
> <html>
> <header>
> <meta name="Description" content="name.JPG">
> <meta name="GENERATOR" content="name">
> <title>
> name.JPG
> </title>
> </header>
> 
> so how do i search for
> 
> </title>
> </header>
> 
> and replace it with
> 
> </title>
> <link rel="stylesheet" href="glob_style.css" type="text/css">
> </header>
> 
> Any ideas?
> 
> thanks!
> 
> todd.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to